How to configure BGP on MikroTik
In this post we will be dealing with how to configure BGP on MikroTik routers. If you have not been on the blog before or watched any of my YouTube videos I try to give as much hands-on and real world examples when dealing with configuration. I would highly suggest watching the video in conjunction with the post in order to maximise your understanding of what BGP is and how to configure it on a MikroTik router.
(If you want to skip all the fluff in the post and jump straight into configuration please scroll down past the What is BGP section)
What is BGP (Border Gateway Protocol)?
Before we try to configure BGP let's first give some insight into what it is and why do we use it? First and foremost BGP is a dynamic routing protocol which we can use to exchange routing information between routers. BGP is actually "THE" routing protcol when it comes to exchanging routing information to and from the Internet.
Unlike a majority of the routing protocols BGP is designed to work between ASNs (Autonomous System Number), you get two different types of BGP, most of the time we will be working with eBGP(Exterior Border Gateway Protocol), however some configurations can make use of iBGP (Interior Gateway Protocol) where BGP connects within the same ASN. We tend to avoid the latter as we tend to use routing protocols like OSPF or IS-IS to handle interior routing.
What makes BGP a great routing protocol is all the attributes that you can also specify between the peers. Giving you control to potentially set how traffic flows and allowing for easy installation for things such as failover.
Without going into all the detail BGP takes two to tango, you will primarily be forming a neighborship with a remote router most of the time on the same broadcast domain. Configuring BGP on MikroTik is very straightforward and you will mainly be working in 3 sections.
1) The BGP instance, this is where you configure your ASN details
2) The BGP peer, this is where you configure your neighbor's ASN details
3) The Networks, here you will be defining which networks BGP is advertising (Note you can redistribute routes through the instance section as well)
Now that we have briefly discussed what BGP is we will look at how to configure this between two routers.
We will be jumping into the configuration shortly, I first want you to look at the below topology to understand what our goals are. Even though we are using private IP ranges these could to public IP ranges which you are advertising to the rest of the world at an INX (Internet Exchange) once we are done with the BGP cofniguration both routers will have an established BGP connections and they will learn each-other's routes.
Let's configure BGP on the router to the left (The Blue Network)
This router has a WAN address of 220.127.116.11/30 which connects to MikroTik2. This router also has the 192.168.0.0/16 subnet sitting behind it which we will want to advertise to MikroTik2. We will be configuring the BGP instance with the 400 ASN, then we will be configuring the BGP peer to MikroTik2 and finally we will add the network we would like to advertise:
routing bgp instance add name=AS400 as=400 router-id=18.104.22.168
routing bgp peer add name=TO_MIKROTIK2 remote-as=300 remote-address=22.214.171.124 instance=AS400
routing bgp network add network=192.168.0.0/16
NB: Do not forget to specify the correct instance in the peer!
Now that we have configured MikroTik1's configuration we are able to start working on MikroTik2. The configuration will be very similar, although very much in reverse and we will be changing the networks we will be advertising. The key to remember is the 3 steps mentioned earlier.
Let's complete the configuration on MikroTik2 below:
routing bgp instance add name=AS300 as=300 router-id=126.96.36.199
routing bgp peer add name=TO_MIKROTIK1 remote-as=400 remote-address=188.8.131.52 instance=AS300
routing bgp network add network=172.16.0.0/16
Completed! Let's verify our work
We've successfully completed the configuration, however you should always verify that everything is connecting and that you are learning the routes, below are some commands you can use to verify that the peer is up as well as checking to confirm if you are receiving routes.
routing bgp peer print
Note when you print the peer if you see an E next to the sequence that means the peer is Established which is good!
ip route print where received-from=TO_MIKROTIK1
You can see specifically which routes you are learning from a certain peer by using the ip route print where received-from="neighbor"
This next command is only to be used within your OWN network if you are creating a BGP connection to one of your own routers. You can inject a default route to a remote router by adding the following command to the BGP peer, in this example I will be setting the default-originate to always in order to send a default route from MikroTik1 to MikroTik2.
routing bgp peer set default-originate=always 0
Note that the 0 is the sequence number for this specific peer, you can always check the sequence numbers by typing routing bgp peer print.
EZ Configuration done!
Everything is working as intended and I will thus be ending the blog post here. Thank you so much for reading the content I hope this post was able to help you learn something new and that you are more prepared to configure and maybe troubleshoot BGP on a MikroTik rouer.