#bgp #networking #ban2bgp

app ban2bgp

BGP blackholer temporary injects given banned IP addresses as blackhole routes into your network to pevent black hats to compromise your services

4 releases

0.1.3 Oct 26, 2023
0.1.2 Oct 26, 2023
0.1.1 Jul 25, 2021
0.1.0 May 23, 2021

#731 in Network programming

Download history 12/week @ 2023-10-31 5/week @ 2023-11-07 10/week @ 2023-11-14 8/week @ 2023-11-21 10/week @ 2023-11-28 4/week @ 2023-12-05 4/week @ 2023-12-12 12/week @ 2023-12-26 1/week @ 2024-01-09 2/week @ 2024-01-23 15/week @ 2024-01-30 2/week @ 2024-02-06 38/week @ 2024-02-13

57 downloads per month





This is a network distributed intrusion prevention system controlled via HTTP API. When bad guys tries to knock your servers or routers, their IP can be immediately blocked for specified amount of time for all your network by two ways:

  1. bad IP's announced as as hotroutes to null to your RR's, so bad guys will not got responses.
  2. bad IP's announced as flowspec rules, blocking any traffic from these addresses. Please be caution with attack sources, because some session-less protocols like DNS is not recommended as attack source, because source IP's can be easy spoofed.

Quick start

At first you will need at least a BGP RR to connect ban2bgp with :-). And some PC with Linux/FreeBSD (although Windows or Mac will work too, I hope) to run ban2bgp.

At second you should configure your router to accept bgp connections from your PC. For example, router you have has IP, AS 65535. PC with ban2bgp has IP In Cisco dialect it will be something like:

! Set nexthop for denied routes to null
ip route Null0
! Set up the BGP
router bgp 65535
 ! create a neighbor with your own AS, so it will be IBGP
 neighbor remote-as 65535
 ! specify source IP
 neighbor update-source Loopback0
 ! do not attempt to connect from router to PC, only from PC to router
 neighbor transport connection-mode passive
 address-family ipv4
 ! it has ipv4 unicast address family
  neighbor activate
 ! send all routing information to PC
  neighbor route-reflector-client

Now on PC with Linux or FreeBSD:

$ git clone https://github.com/wladwm/ban2bgp
... git messages
$ cd ban2bgp
$ cargo build
... cargo messages
$ cat > ban2bgp.ini <<EOF


$ RUST_LOG=info cargo run
Listening on
Connecting to
Connected to

After this you can check on your router that BGP session with is established. Add denyroute for host for an hour via http request: /usr/bin/curl

Or you can use bundled minimal SPA by pointing your browser to

In ther contrib folder you can find an example configuration for fail2ban. when you specify in the jain config banaction=ban2bgp instead of banaction=iptables...

Bad hosts will be banned not for just single server, but for your whole network. Also you can easily integrate ban2bgp on your syslog server for all your routers.


ban2bgp looks for configuration in file ban2bgp.ini in current directory. This file have on [main] section Main section parameters:

  • httplisten - bind address and port for inner http server, default
  • http_files_root - http serve files from this location, default ./contrib/
  • listen - not necessary BGP listen point, default, which required root privileges because 179<1024.
  • nexthop - ipv4 nexthop for denied routes. All your routers should have this routed to Null.
  • nexthop6 - ipv6 nexthop for denied routes.
  • communities - spaced-separated communites list for denied routes.
  • peers - comma-separated (or space- or tab-separated) list for BGP peers. Each peer should have a separate section in ini file.
  • duration - default denied route time to live in seconds.
  • skiplist - comma-separated list for networks, which are skipped in add requests. Peer section parameters:
  • peer - peer ip address
  • as - peer AS
  • mode - peer mode - blackhole or flowspec

API endpoints

  • /api/add Parameters:

    • net - ipv4/ipv6 route to anounce
    • dur - ttl in seconds
  • /api/remove Parameters:

    • net - ipv4/ipv6 route to be removed from announces
  • /api/json Block operation. Requires a valid JSON Object in POST body with optional keys "add" and "remove". remove - an array of string routes to be removed, add - an object with "duration" and "nets". "nets" - an array of string routes to be added for "duration" seconds. Example: {"add":{"duration":86400,"nets":[""]},"remove":["",""]}

  • /api/ping Checks service liveness. Returns "pong"

  • /api/status Returns JSON object with per peer status and count opf ipv4 and ipv6 routes {'peers':{'':'InSync'},'routes':{'ipv4':0,'ipv6':0}}

  • /api/dumprib Returns text table with active routes and times

  • /api/dumpribjson Returns json object with active routes and times






MIT OR Apache-2.0


~299K SLoC