MikroTik RouterOS — BGP

I have always wanted to learn about BGP. This time I got the honor chance to implement BGP for an ISP. This ISP has its own AS number and a /21 IP address block. This BGP setup is pretty simple because I’m only using 1 PC (with 3 ethernet cards and a MikroTik’s level 4 DOM) to interconnect with an Internet Exchange (IX) — NiCE — and a transit ISP (another transit will be added soon).

In MikroTik RouterOS version 2.9.42, BGP features are available for level 3 and above. You also need to enable routing-test package if you want more flexibility (BGP filtering features). The routing package, as of this version, only allows basic BGP features. I’m sure this will change later when they release RouterOS v3. Once you have enabled routing-test package, you will see new options (Routing – Filters in winbox, or /routing filters on CLI). This is very important when you have to peer with 2 or more ASes (specifically an IX and a transit which is not interested in getting IX’s routes for obvious reasons).

Since I have never configured BGP before, I caused a major problem when routes from each peer goes to another peer when they shouldn’t! I didn’t place any filter for BGP advertisements my BGP router sends to its peers. My transit ISP received the IX’s routes and the IX received full Internet routes feed my BGP router gets from the transit ISP. BGP is an exterior distance-vector routing protocol, it picks its best path by comparing the AS path lengths of every route it has. Advertising the whole Internet BGP feed to the local IX caused other ISPs’ routers participating in the IX to discover a shorter path of international routes going via my BGP router so the routers chose this new shorter path instead and outgoing traffic of these ISPs started to flow via my transit ISP! On the other hand, advertising IX routes to my transit was not a big problem since the path will be farther for their customers anyway, having to go via my BGP router first (that’s one AS further for the transit ISP’s customers to reach the IX routes, so BGP will not select it).

Fortunately I was able to spot the error immediately and placed BGP routing filters to include only my /21 IP block in the advertisements my BGP router sends to both the IX and transit. I also added an incoming BGP filter to discard a default route my transit IP includes in its BGP feed. This default route is not required since I get full BGP feed that is unfiltered.

Useful links:
http://wiki.mikrotik.com/wiki/BGP_Case_Studies_1 — Route filters examples
http://wiki.mikrotik.com/wiki/Using_scope_and_target-scope_attributes — Important! Make sure that BGP neighbors are reachable via static routes for dynamic routes to be active (in the case of multihop BGP neighbors)
Cisco’s BGP Reference

3 thoughts on “MikroTik RouterOS — BGP

  1. whereis the example configuration, could you share? may be with fake ip address,
    thanks 4 advance

  2. Hi Arif,

    This is the example:
    from /routing filter
    0 ;;; Advertise to OpenIXP in /24s
    chain=to_OpenIXP prefix= prefix-length=24 invert-match=no action=accept

    1 ;;; Advertise to OpenIXP in /24s
    chain=to_OpenIXP prefix= prefix-length=24 invert-match=no action=accept

    2 ;;; Advertise only our prefixes to OpenIXP, do not redistribute transit routes to IX
    chain=to_OpenIXP invert-match=no action=discard

    3 ;;; Discard default route from OpenIXP
    chain=from_OpenIXP prefix= invert-match=no action=discard

    4 ;;; IX routes should get higher priority
    chain=from_OpenIXP invert-match=no action=accept set-bgp-local-pref=200

    5 ;;; Advertise to NAP
    chain=to_NAP prefix= prefix-length=20 invert-match=no action=accept

    6 ;;; Advertise to NAP
    chain=to_NAP prefix= prefix-length=21 invert-match=no action=accept

    7 ;;; Advertise only our prefixes to NAP, do not redistribute IX routes/other transit routes to this transit
    chain=to_NAP invert-match=no action=discard

    8 X ;;; Only use default route from NAP’s BGP feed, opposite the following rule
    chain=from_NAP prefix= invert-match=yes action=discard

    9 ;;; Discard default route from NAP
    chain=from_NAP prefix= invert-match=no action=discard

    from /routing bgp network
    0 A no
    1 A no
    2 A no
    3 A no
    4 A no
    5 A no
    6 A no
    7 A no
    8 A no
    9 A no
    10 A no
    11 A no
    12 A no
    13 A no
    14 A no
    15 A no
    16 A no
    17 A no
    18 A no
    19 A no
    20 A no
    21 A no
    22 A no
    23 A no
    24 A no
    25 A no

    Please note that OpenIXP advertises the smaller prefixes (/24) to make sure that local IX traffic takes the OpenIXP path rather than the NAP path. I also choose to drop default route from NAP to receive full BGP feed from my NAP. If you wish to receive only the default route (make sure your NAP does provide a default route otherwise your packets will go nowhere), enable filter #8 and disable #9.

    Good luck!

Leave a Reply

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

Anti-Spam by WP-SpamShield