I’m really excited about these next few posts. I’ve been doing some research on BGP and automating routing decisions with python, which led to my discovery of ExaBGP. ExaBGP is dubbed “The BGP swiss army knife”, and I’m early in my experimentation with this tool, but it seems to be a very easy way to peer with your BGP routers and control the advertisement of networks.

This post will cover basic setup of ExaBGP and peering with a router, as well as how you can tie in python to present control for the advertisement of routes. The next post will use the Flask web framework to offer a simple HTTP API for adding/removing routes. I hope the following posts will be along the lines of receiving the BGP UPDATE messages from peered routers to monitor and analyze advertised networks.

Step 1: Install ExaBGP

The installation is very simple, you just install via pip in your global python packages, or preferably in a virtualenv (or similar) to not interfere with your other projects:

$ pip3 install exabgp (or pip if you’re using python 2)

This should work on OS X and *nix, but I did have some problems trying to run ExaBGP on Windows.

Step 2: Configure your Router

I’m using a Cisco CSR-1000V virtual router instance on the same machine I’m running python/ExaBGP on, but you can also use any router that has IP connectivity to the machine you are running ExaBGP with. Note that my CSR-1000V router has the IP address of, and my ExaBGP machine has an IP address of Here’s my router’s very basic BGP config and local IP addresses.

If you run a show bgp summary command, you will see the neighbor in BGP Idle state since our ExaBGP side hasn’t tried peering yet.  I also recommend using debug bgp all (only in a lab of course) to monitor the connection status and updates from ExaBGP:

Step 3: Configure ExaBGP

Now we can configure ExaBGP to peer with our router using a conf.ini file. Explanations for each directive are commented inline:

If we start ExaBGP now, we’ll see the neighbors peer successfully and the ExaBGP process will receive BGP UPDATE messages for any prefixes the CSR router is currently advertising. Here’s what we see when starting ExaBGP:

And running show bgp summary on the router also confirms that the peering is in an Established state:

Well, that’s certainly a start!

Step 4: Write python Script to add/remove Routes

Using an example from ExaBGP, we’re going to create a very simple python script named example.py to advertise two prefixes to our CSR router:

The reason this script works is that ExaBGP monitors STDOUT while running and parses for commands such as “announce route …” and “withdraw route …”. Check out this full list of API commands, I’ll be covering several of these in the upcoming articles. Now we just need to update our conf.ini file to run this python script upon startup of ExaBGP:

Here’s the output from exabgp:

And after this finishes, we can confirm the new prefixes on our router by running show bgp:

Congrats! We just used python to inject routes into the BGP and RIB tables on a router. I know this example is a little boring since you have to preconfigure the prefixes and use sleep timers, but I’ll cover how to make this a little more interactive in the next post.

Series NavigationUsing service health checks to automate ExaBGP >>

This post was originally published on

This article has 5 comments

    1. Mat

      No, and in fact it shouldn’t since a session reset will cause all learned routes from ExaBGP to be removed by the router. If you are using a python script like the example, the script will only run once until you stop/start ExaBGP which does reset the session. To dynamically manage routes without dropping the session checkout the other ExaBGP articles. Let me know if you have any other questions.

Leave a Reply to Siva Cancel reply

Your email address will not be published. Required fields are marked *