Manual:BGP Load Balancing with two interfaces
NB: RouterOS version 3.13 or later with routing-test package is required for this to work
In these examples we show how to do load balancing when there are multiple equal cost links between two BGP routers. The BGP session is established between loopback interfaces; update-source configuration setting is used for this purpose.
Example with iBGP
On Router A:
# loopback interface /interface bridge add name=lobridge # addresses /ip address add address=184.108.40.206/24 interface=ether1 /ip address add address=220.127.116.11/24 interface=ether2 /ip address add address=18.104.22.168/32 interface=lobridge # ECMP route to peer's loopback /ip route add dst-address=22.214.171.124/32 gateway=126.96.36.199,188.8.131.52 # BGP /routing bgp instance set default as=65000 /routing bgp add name=peer1 remote-address=184.108.40.206 remote-as=65000 update-source=lobridge
On Router B:
# loopback interface /interface bridge add name=lobridge # addresses /ip address add address=220.127.116.11/24 interface=ether1 /ip address add address=18.104.22.168/24 interface=ether2 /ip address add address=22.214.171.124/32 interface=lobridge # ECMP route to peer's loopback /ip route add dst-address=126.96.36.199/32 gateway=188.8.131.52,184.108.40.206 # BGP /routing bgp instance set default as=65000 /routing bgp add name=peer1 remote-address=220.127.116.11 remote-as=65000 update-source=lobridge # a route to advertise /routing bgp network add network=18.104.22.168/24
Check that BGP connection is established:
[admin@B] > /routing bgp peer print status Flags: X - disabled 0 name="peer1" instance=default remote-address=22.214.171.124 remote-as=65000 tcp-md5-key="" nexthop-choice=default multihop=no route-reflect=no hold-time=3m ttl=255 in-filter="" out-filter="" address-families=ip update-source=lobridge default-originate=no remote-id=126.96.36.199 local-address=188.8.131.52 uptime=28s prefix-count=0 updates-sent=1 updates-received=0 withdrawn-sent=0 withdrawn-received=0 remote-hold-time=3m used-hold-time=3m used-keepalive-time=1m refresh-capability=yes as4-capability=yes state=established
Route table on Router A:
[admin@A] > /ip route print Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit # DST-ADDRESS PREF-SRC G GATEWAY DISTANCE INTER... 0 ADC 184.108.40.206/24 220.127.116.11 0 ether1 1 ADC 18.104.22.168/24 22.214.171.124 0 ether2 2 ADb 126.96.36.199/24 r 188.8.131.52 200 ether1 ether2 3 ADC 184.108.40.206/32 220.127.116.11 0 lobridge 4 A S 18.104.22.168/32 r 22.214.171.124 1 ether1 r 126.96.36.199 ether2
[admin@A] > /ip route print detail Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, B - blackhole, U - unreachable, P - prohibit 0 ADC dst-address=188.8.131.52/24 pref-src=184.108.40.206 interface=ether1 distance=0 scope=10 1 ADC dst-address=220.127.116.11/24 pref-src=18.104.22.168 interface=ether2 distance=0 scope=10 2 ADb dst-address=22.214.171.124/24 gateway=126.96.36.199 interface=ether1,ether2 gateway-state=recursive distance=200 scope=40 target-scope=30 bgp-local-pref=100 bgp-origin=igp received-from=188.8.131.52 3 ADC dst-address=184.108.40.206/32 pref-src=220.127.116.11 interface=lobridge distance=0 scope=10 4 A S dst-address=18.104.22.168/32 gateway=22.214.171.124,126.96.36.199 interface=ether1,ether2 gateway-state=reachable,reachable distance=1 scope=30 target-scope=10
The route 188.8.131.52./24 is installed in Linux kernel now with two nexthops: 184.108.40.206 (on ether1) and 220.127.116.11 (on ether2).
Example with eBGP
Here the example given above is further developed for eBGP case. By default, eBGP peers are required to be directly reachable. If we are using loopback interfaces, they technically are not, so multihop=yes configuration setting must be specified.
On Router A:
/routing bgp instance set default as=65000 /routing bgp set peer1 remote-address=18.104.22.168 remote-as=65001 update-source=lobridge multihop=yes
On Router B:
/routing bgp instance set default as=65001 /routing bgp set peer1 remote-address=22.214.171.124 remote-as=65000 update-source=lobridge multihop=yes
If we now print the route table on Router A, we see that the route from Router B is there, but it's not active:
... 2 Db dst-address=126.96.36.199/24 gateway=188.8.131.52 interface="" gateway-state=unreachable distance=20 scope=40 target-scope=10 bgp-as-path="65001" bgp-origin=igp received-from=184.108.40.206 ...
This is because eBGP routes are installed with lesser target-scope by default. To solve this, setup routing filter that sets bigger target-scope:
/routing filter add chain=bgp-in set-target-scope=30 /routing bgp set peer1 in-filter=bgp-in
Or else, modify scope attribute of the static route:
/ip route set [find dst-address=220.127.116.11/32] scope=10
Either way, the route to 18.104.22.168/24 should be active now:
2 ADb dst-address=22.214.171.124/24 gateway=126.96.36.199 interface=ether1,ether2 gateway-state=recursive distance=20 scope=40 target-scope=10 bgp-as-path="65001" bgp-origin=igp received-from=188.8.131.52
- BGP itself as protocol does not supports ECMP routes. When a recursively resolved BGP route is propagated further in the network, only one nexthop is selected (as described here) and included in the BGP UPDATE message.
- Corresponding Cisco syntax can be found here: Load Sharing with BGP in Single and Multihomed Environments: Sample Configurations