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 "multiple recursive next-hop resolution" feature is used to achieve that.
The BGP session is established between loopback interfaces; update-source configuration setting is used to bind the BGP connection to the right interface.
Example with iBGP
On Router A:
# loopback interface /interface bridge add name=lobridge # addresses /ip address add address=126.96.36.199/24 interface=ether1 /ip address add address=188.8.131.52/24 interface=ether2 /ip address add address=184.108.40.206/32 interface=lobridge # ECMP route to peer's loopback /ip route add dst-address=220.127.116.11/32 gateway=18.104.22.168,22.214.171.124 # BGP /routing bgp instance set default as=65000 /routing bgp add name=peer1 remote-address=126.96.36.199 remote-as=65000 update-source=lobridge
On Router B:
# loopback interface /interface bridge add name=lobridge # addresses /ip address add address=188.8.131.52/24 interface=ether1 /ip address add address=184.108.40.206/24 interface=ether2 /ip address add address=220.127.116.11/32 interface=lobridge # ECMP route to peer's loopback /ip route add dst-address=18.104.22.168/32 gateway=22.214.171.124,126.96.36.199 # BGP /routing bgp instance set default as=65000 /routing bgp add name=peer1 remote-address=188.8.131.52 remote-as=65000 update-source=lobridge # a route to advertise /routing bgp network add network=184.108.40.206/24
Check that BGP connection is established:
[admin@B] > /routing bgp peer print status Flags: X - disabled 0 name="peer1" instance=default remote-address=220.127.116.11 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=18.104.22.168 local-address=22.214.171.124 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 126.96.36.199/24 188.8.131.52 0 ether1 1 ADC 184.108.40.206/24 220.127.116.11 0 ether2 2 ADb 18.104.22.168/24 r 22.214.171.124 200 ether1 ether2 3 ADC 126.96.36.199/32 188.8.131.52 0 lobridge 4 A S 184.108.40.206/32 r 220.127.116.11 1 ether1 r 18.104.22.168 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=22.214.171.124/24 pref-src=126.96.36.199 interface=ether1 distance=0 scope=10 1 ADC dst-address=188.8.131.52/24 pref-src=184.108.40.206 interface=ether2 distance=0 scope=10 2 ADb dst-address=220.127.116.11/24 gateway=18.104.22.168 interface=ether1,ether2 gateway-state=recursive distance=200 scope=40 target-scope=30 bgp-local-pref=100 bgp-origin=igp received-from=22.214.171.124 3 ADC dst-address=126.96.36.199/32 pref-src=188.8.131.52 interface=lobridge distance=0 scope=10 4 A S dst-address=184.108.40.206/32 gateway=220.127.116.11,18.104.22.168 interface=ether1,ether2 gateway-state=reachable,reachable distance=1 scope=30 target-scope=10
The route 22.214.171.124./24 is installed in Linux kernel now with two nexthops: 126.96.36.199 (on ether1) and 188.8.131.52 (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=184.108.40.206 remote-as=65001 update-source=lobridge multihop=yes
On Router B:
/routing bgp instance set default as=65001 /routing bgp set peer1 remote-address=220.127.116.11 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=18.104.22.168/24 gateway=22.214.171.124 interface="" gateway-state=unreachable distance=20 scope=40 target-scope=10 bgp-as-path="65001" bgp-origin=igp received-from=126.96.36.199 ...
This is because eBGP routes are installed with lesser target-scope by default. To solve this, setup routing filter that sets larger 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=188.8.131.52/32] scope=10
Either way, the route to 184.108.40.206/24 should be active now:
2 ADb dst-address=220.127.116.11/24 gateway=18.104.22.168 interface=ether1,ether2 gateway-state=recursive distance=20 scope=40 target-scope=10 bgp-as-path="65001" bgp-origin=igp received-from=22.214.171.124
- BGP itself as protocol does not supports ECMP routes. When a recursively resolved BGP route is propagated further in the network, only one nexthop can be 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