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=18.104.22.168/24 interface=ether1 /ip address add address=22.214.171.124/24 interface=ether2 /ip address add address=126.96.36.199/32 interface=lobridge # ECMP route to peer's loopback /ip route add dst-address=188.8.131.52/32 gateway=184.108.40.206,220.127.116.11 # BGP /routing bgp instance set default as=65000 /routing bgp add name=peer1 remote-address=18.104.22.168 remote-as=65000 update-source=lobridge
On Router B:
# loopback interface /interface bridge add name=lobridge # addresses /ip address add address=22.214.171.124/24 interface=ether1 /ip address add address=126.96.36.199/24 interface=ether2 /ip address add address=188.8.131.52/32 interface=lobridge # ECMP route to peer's loopback /ip route add dst-address=184.108.40.206/32 gateway=220.127.116.11,18.104.22.168 # BGP /routing bgp instance set default as=65000 /routing bgp add name=peer1 remote-address=22.214.171.124 remote-as=65000 update-source=lobridge # a route to advertise /routing bgp network add network=126.96.36.199/24
Check that BGP connection is established:
[admin@B] > /routing bgp peer print status Flags: X - disabled 0 name="peer1" instance=default remote-address=188.8.131.52 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=184.108.40.206 local-address=220.127.116.11 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 18.104.22.168/24 22.214.171.124 0 ether1 1 ADC 126.96.36.199/24 188.8.131.52 0 ether2 2 ADb 184.108.40.206/24 r 220.127.116.11 200 ether1 ether2 3 ADC 18.104.22.168/32 22.214.171.124 0 lobridge 4 A S 126.96.36.199/32 r 188.8.131.52 1 ether1 r 184.108.40.206 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=220.127.116.11/24 pref-src=18.104.22.168 interface=ether1 distance=0 scope=10 1 ADC dst-address=22.214.171.124/24 pref-src=126.96.36.199 interface=ether2 distance=0 scope=10 2 ADb dst-address=188.8.131.52/24 gateway=184.108.40.206 interface=ether1,ether2 gateway-state=recursive distance=200 scope=40 target-scope=30 bgp-local-pref=100 bgp-origin=igp received-from=220.127.116.11 3 ADC dst-address=18.104.22.168/32 pref-src=22.214.171.124 interface=lobridge distance=0 scope=10 4 A S dst-address=126.96.36.199/32 gateway=188.8.131.52,184.108.40.206 interface=ether1,ether2 gateway-state=reachable,reachable distance=1 scope=30 target-scope=10
The route 220.127.116.11./24 is installed in Linux kernel now with two nexthops: 18.104.22.168 (on ether1) and 22.214.171.124 (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=126.96.36.199 remote-as=65001 update-source=lobridge multihop=yes
On Router B:
/routing bgp instance set default as=65001 /routing bgp set peer1 remote-address=188.8.131.52 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=184.108.40.206/24 gateway=220.127.116.11 interface="" gateway-state=unreachable distance=20 scope=40 target-scope=10 bgp-as-path="65001" bgp-origin=igp received-from=18.104.22.168 ...
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=22.214.171.124/32] scope=10
Either way, the route to 126.96.36.199/24 should be active now:
2 ADb dst-address=188.8.131.52/24 gateway=184.108.40.206 interface=ether1,ether2 gateway-state=recursive distance=20 scope=40 target-scope=10 bgp-as-path="65001" bgp-origin=igp received-from=220.127.116.11
- 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