Originating Default Route in OSPF in Junos

I have a Junos router (Juniper SRX) with the default route pointing to the ISP (IP and default route assigned by DHCP) and a pair of Cisco Nexus switches with OSPF routing between all the boxes. I needed to originate a default route from SRX to Nexus switches.

First, in order to be able to announce the 0.0.0.0/0 route to the Nexus switches the SRX needs to have the route in it’s routing table. Usually that is the case but if the ISP link goes down then the default route will disappear from the routing table. That would be a problem in this implementation because there are some subnets in SRX that are reachable for the inside networks via the default route. (It would be possible to inject the specific routes in OSPF as well but this was the selected way of implementation right now.) In other words, I wanted to implement Cisco-style “default-information originate always functionality. Therefore I generated a discard default route that will be used if the ISP default will disappear:

admin@SRX# show routing-options
generate {
    route 0.0.0.0/0 discard;
}

[edit]
admin@SRX# run show route
...
0.0.0.0/0          *[Access-internal/12] 00:56:39
                    > to 85.xxx.xxx.1 via ge-0/0/0.0
                    [Aggregate/130] 00:25:11
                      Discard

Note that the discard route is not active at the moment because the ISP-supplied DHCP route has better preference (12) than the generated route (130).

Second, I needed a policy that takes the default route and accepts it:

admin@SRX# show policy-options
policy-statement DEFAULT_ORIGINATE {
    term DEFAULT_ROUTE {
        from {
            route-filter 0.0.0.0/0 exact;
        }
        then {
            accept;
        }
    }
}

Finally, I attached the policy in the OSPF process:

admin@SRX# show protocols ospf
export DEFAULT_ORIGINATE;
area 0.0.0.0 {
    interface ge-0/0/14.0 {
        ...
    }
    interface ge-0/0/15.0 {
        ...
    }
}

Verification in the Nexus switch:

NEXUS01# sh ip route ospf
...
0.0.0.0/0, ubest/mbest: 1/0
    *via 10.1.0.1, Eth1/1, [110/0], 00:23:13, ospf-1, type-2

Thanks Per Westerlund (@PerWesterlund) and Marko Milivojevic (@icemarkom) for commenting my questions regarding these configurations.

3 Comments

Add a Comment
  1. I believe the “next-hop self” is mostly relevant with BGP, with OSPF it will be enough just to “accept”. Announcing as an external route with OSPF implicitly says “send to me”.

    1. Good point, forgot to check that! I’ll remove it here.

  2. As shown above the route type will be external type 2 by default. If you want to get type 1 instead add this to the policy:

    set policy-options policy-statement DEFAULT_ORIGINATE term DEFAULT_ROUTE then external type 1

Leave a Reply