Default route from OSPF not getting installed if static route exists

I have a problem with OSPF default route not getting installed if another default route exists.

There are two routers, R1 and R2, both on 6.37.1

  • Both routers have an uplink to one ISP and a default route to them.
  • The distance for the static default route in R1 is 1, this is a 100Mbps link
  • The distance for the static default route in R2 is 250, this is a 10Mbps backup link
  • I am running OSPF to distribute routes between these two routers with the aim of having R2 use R1 as the default route if R1 has a default route installed. The 10Mbps backup link should not be used if the 100Mbps one is reachable through R1.

Now for the weird behaviour on R2 - it does not install the OSPF-sourced default route into the RIB if there is a static default route with ANY distance already there. I can’t understand why.

step 1: Only static default route to ISP (10Mbps backup link) is active, OSPF is shut down

[admin@vSGtik] > /ip route pr           
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        GATEWAY            DISTANCE
 0 A S  ;;; High-distance static route to ISP as last resort, normally defau
        0.0.0.0/0                          194.100.202.165         250

Now I enable OSPF instance:

[admin@vSGtik] > /routing ospf instance enable 1
[admin@vSGtik] > /ip route pr                   
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        GATEWAY            DISTANCE
 0 A S  ;;; High-distance static route to ISP as last resort, normally defau
        0.0.0.0/0                          194.100.202.165         250
...

So no new default route appears with distance 110.. Other OSPF routes do appear. Check OSPF LSA:

[admin@vSGtik] > /routing ospf lsa pr det
...
 instance=ospf1 area=external type=as-external id=0.0.0.0 originator=<R2 IP> sequence-number=0x80000001 
   age=68 checksum=0xA839 options="E" body=
     netmask=0.0.0.0
     forwarding-address=0.0.0.0
     metric=200
     route-tag=0x0
     type2

 instance=ospf1 area=external type=as-external id=0.0.0.0 originator=<R1 IP> sequence-number=0x8000003A 
   age=119 checksum=0x620D options="E" body=
     netmask=0.0.0.0
     forwarding-address=0.0.0.0
     metric=1
     route-tag=0x0
     type2
...

The default route from R1 is there with metric 1.. So let’s try disabling the static route:

[admin@vSGtik] > /ip route disable 0
[admin@vSGtik] > /ip route pr       
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        GATEWAY            DISTANCE
 0 ADo  0.0.0.0/0                          <R1 IP>                  110
 1 X S  0.0.0.0/0                          194.100.202.165         250
...

Ok so we have a OSPF default route! Let’s enable the static route again.

[admin@vSGtik] > /ip route enable 1
[admin@vSGtik] > /ip route pr      
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        GATEWAY            DISTANCE
 0 ADo  0.0.0.0/0                          <R1 IP>                 110
 1   S  0.0.0.0/0                          194.100.202.165         250
...

Working as it should, static route appears but OSPF is active due to smaller distance. For the first time we have both default routes installed.
So to test, I disable default route from R1 and check changes on R2:

[admin@vSGtik] > /ip route pr
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        GATEWAY            DISTANCE
 0 A S  0.0.0.0/0                          194.100.202.165         250
...
[admin@vSGtik] > /routing ospf lsa pr    
AREA                                        TYPE         ID             ORIGINATOR     SEQUENCE-NUMBER        AGE
...
external                                    as-external  0.0.0.0        <R2 IP>            0x80000001         13
...

Also worked as expected. No LSA and the static route became active when the OSPF one disappeared. So I re-enabled the static route on R2 and check R1 again:

[admin@vSGtik] > /ip route pr        
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf, m - mm
B - blackhole, U - unreachable, P - prohibit 
 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 0 A S  0.0.0.0/0                          194.100.202.165         250
...
[admin@vSGtik] > /routing ospf lsa pr
AREA                                        TYPE         ID             ORIGINATOR     SEQUENCE-NUMBER   
...
external                                    as-external  0.0.0.0        <R2 IP>           0x80000001   
external                                    as-external  0.0.0.0        <R1 IP>           0x80000001   
...

Back to square one. So OSPF LSA from R1 appears but the default route does not.

What am I not understanding here or this a bug?

Note: This kind of thing also seems to happen if I accept default route via BGP in R2 instead of using a static one. The BGP route has a higher metric than the OSPF one but it stops the OSPF route from being installed into the RIB.

If there is already static default route and you want OSPF to install default route then remove “distribute-default” in ospf instance for that router.

But in my case both routers should advertise the default route to each other (if they have one installed). If the ISP link on R1 fails, it will no longer have a default route unless it gets it from R2 where the backup link is. So I can’t stop distributing the default route from either router if I am to use OSPF.

Also I can’t use static routes because I will end up with a routing loop.. R2 sends traffic to R1 where the ISP link is down so it sends back to R2 and so on…

Would this work better with iBGP instead of OSPF between R1 and R2? Then I would need VRRP towards my firewall.. Any other options?

If both routers have set to redistribute default route and both of them have static or other protocol default route already in routing table, then OSPF default route will not be installed. Unfortunately that is the consequence of current OSPF loop detection implementation.

Ok understood.. I don’t like it but I understand :slight_smile: Would this work with default route being shared via iBGP between the routers? Or some other solution? Right now I have it working with some static routes with carefully chosen metrics and ping gateway checks but would prefer a real routing protocol.