User/Mutual internet backup between two small ISP
Contents
Motivation
Assume two small ISP which operate in surrounding area and have own physical link between them. Both network use dynamic routing OSPF with own backbone and have their own upstream internet connection. As they operate in different area they don't compete to each other and so they have settle on mutual supplying backup internet connection for case of failure of their main link or part of their network.
Realization
Starting conditions
Both networks have their own independent OSPF routing table and one default gateway. Both network are addressable form each other thanks to static routing. Internetwork neutral subnet is addressable too as connected subnets are imported to OSFP.
ABR1:
/ip address
add address=172.16.0.1/30 broadcast=172.16.0.3 comment="" disabled=no interface=wlan1 network=172.16.0.0
add address=1.0.0.1/8 broadcast=1.255.255.255 comment="" disabled=no interface=ether1 network=1.0.0.0
/ip route
(imported form OSPF) add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=1.0.0.2 scope=30 target-scope=10
add comment=ISP2 disabled=no distance=1 dst-address=2.0.0.0/8 gateway=172.16.0.2 scope=30 target-scope=10
/routing ospf instance
set default comment="" disabled=no distribute-default=no in-filter=ospf-in metric-bgp=20 \
metric-connected=20 metric-default=1 metric-other-ospf=auto metric-rip=20 metric-static=20 name=default \
out-filter=ospf-out redistribute-bgp=no redistribute-connected=as-type-1 redistribute-other-ospf=no redistribute-rip=\
no redistribute-static=as-type-1 router-id=0.0.0.0
/routing ospf area
set backbone area-id=0.0.0.0 comment="" disabled=no instance=default name=backbone type=default
/routing ospf network
add area=backbone comment="" disabled=no network=1.0.0.0/8
ABR2:
/ip address
add address=172.16.0.2/30 broadcast=172.16.0.3 comment="" disabled=no interface=wlan1 network=172.16.0.0
add address=2.0.0.1/8 broadcast=2.255.255.255 comment="" disabled=no interface=ether1 network=2.0.0.0
/ip route
(imported form OSPF) add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=2.0.0.2 scope=30 target-scope=10
add comment=ISP1 disabled=no distance=1 dst-address=1.0.0.0/8 gateway=172.16.0.1 scope=30 target-scope=10
/routing ospf instance
set default comment="" disabled=no distribute-default=no in-filter=ospf-in metric-bgp=20 \
metric-connected=20 metric-default=1 metric-other-ospf=auto metric-rip=20 metric-static=20 name=default \
out-filter=ospf-out redistribute-bgp=no redistribute-connected=as-type-1 redistribute-other-ospf=no redistribute-rip=\
no redistribute-static=as-type-1 router-id=0.0.0.0
/routing ospf area
set backbone area-id=0.0.0.0 comment="" disabled=no instance=default name=backbone type=default
/routing ospf network
add area=backbone comment="" disabled=no network=2.0.0.0/8
Setup secondary default gateway
As both network use OSPF routing protocol they can get advantage of automatic propagation of multiple default gateways with defined priority. So they have to inject each other primary default gateway as secondary default gateway to own routing table.
- We need to add to both routers new default gateway with destination to each other. But as static default gateway will take over dynamically imported primary default gateway we need to insert default gateway to different routing table.
ABR1:
/ip route add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=172.16.0.2 routing-mark=backup scope=30 target-scope=10
ABR2:
/ip route add comment="" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=172.16.0.1 routing-mark=backup scope=30 target-scope=10
- Then we need also to mark right packets using firewall mangle to our new routing table. All packets originating from other network with destination different than local network should be directed to backup routing table.
ABR1:
/ip firewall mangle add action=mark-routing chain=prerouting comment="" disabled=no new-routing-mark=backup passthrough=no src-address=2.0.0.0/8 dst-address=!1.0.0.0/8
ABR2:
/ip route add action=mark-routing chain=prerouting comment="" disabled=no new-routing-mark=backup passthrough=no src-address=1.0.0.0/8 dst-address=!2.0.0.0/8
- Default gateway is not yet imported to OSPF so we need to set OSPF to import default gateway and set higher metric value for example 5000. All default gateways should have to same metric type. If secondary default gateway have type1 and primary type2 than secondary will be elected even if primary would have lower metric.
Both ABR1 and ABR2:
/routing ospf instance
set default comment="" disabled=no distribute-default=if-installed-as-type-2 in-filter=ospf-in metric-bgp=20 \
metric-connected=20 metric-default=5000 metric-other-ospf=auto metric-rip=20 metric-static=20 name=default \
out-filter=ospf-out redistribute-bgp=no redistribute-connected=as-type-1 redistribute-other-ospf=no redistribute-rip=no redistribute-static=as-type-1 router-id=0.0.0.0
- You can check presence of default gateways in OSPF table /routing ospf lsa. You can use traceroute for connection route checking.