Juniper OSPF Conditional Default Route

By | December 9, 2013
Warning: Trying to access array offset on value of type null in /customers/3/0/4/robug.net/httpd.www/blog/wp-content/plugins/twitter-facebook-google-plusone-share/tf_display.php on line 72

In this post we will set up a conditional default route for ospf. First we have the following network diagram.

ospf_default_relible

The router junos1 has a bgp session to R1 and is connected to junos2 and using IBGP and OSPF. Junos2 is then connected to Junos3 via IBGP and OSPF.

[edit]
root# show protocols bgp
group External {
    export BGP_Redis;
    neighbor 192.168.11.1 {
        peer-as 100;
    }
}
group IBGP {
    type internal;
    export BGP_Redis;
    neighbor 20.20.20.20 {
        local-address 10.10.10.10;
    }
}

[edit]
root# show policy-options policy-statement BGP_Redis
term Loopback {
    from {
        protocol direct;
        route-filter 10.10.10.10/8 exact;
    }
    then accept;
}
then accept;
root# run show bgp summary
Groups: 2 Peers: 2 Down peers: 0
Table          Tot Paths  Act Paths Suppressed    History Damp State    Pending
inet.0      145        144          0          0          0          0
Peer           AS  InPkt OutPkt  OutQ  Flaps Last Up/Dwn State|#Active/Received/Accepted/Damped...
20.20.20.20    200  3212   4386     0    2    23:13:46 48/48/48/0           0/0/0/0
192.168.11.1   100    21     15     0  731        2:57 96/97/97/0           0/0/0/0

We are reserving routes from R1 and want this to be our default gateway out of our network. The first thing we need to do is to set up a policy for the default route.

[edit]
root# show policy-options policy-statement genroute
term 1 {
    from {
        protocol bgp;
        route-filter 1.0.0.0/8 exact;
    }
    then accept;
}
term end {
    then reject;
}

This policy matches a route learnt from bgp and matach 1.0.0.0/8 network address. This is an address learnt from R1. We now need to set up the static route.

[edit]
root# show routing-options
generate {
    route 0.0.0.0/0 policy genroute;
}

This crates a route 0.0.0.0/0 on the condition of the policy “genroute”. Once this is done if you have learnt 1.0.0.0/8 via bgp then you will get a default route.

[edit]
root# run show route

inet.0: 157 destinations, 158 routes (157 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

0.0.0.0/0          *[Aggregate/130] 00:57:03
                    > to 192.168.11.1 via em0.0
1.0.0.0/8          *[BGP/170] 00:03:46, MED 0, localpref 100
                      AS path: 100 ?
                    > to 192.168.11.1 via em0.0
2.0.0.0/8          *[BGP/170] 00:03:46, MED 0, localpref 100
                      AS path: 100 ?
                    > to 192.168.11.1 via em0.0
3.0.0.0/8          *[BGP/170] 00:03:46, MED 0, localpref 100
                      AS path: 100 ?

Now if we remove the route 1.0.0.0/8 from R1 this will then remove the default route from the routing table.

!
ip access-list standard lo1
 permit 1.0.0.0 0.255.255.255
 permit 192.168.11.0 0.0.0.255
!
!
route-map redis_conn deny 10
 match ip address lo1
!
route-map redis_conn permit 20
!
router bgp 100
 redistribute connected route-map redis_conn

now we have blocked the route 1.0.0.0/8 from being advertised let have a look at the routes on Junos1

[edit]
root# run show route

inet.0: 108 destinations, 109 routes (107 active, 0 holddown, 1 hidden)
+ = Active Route, - = Last Active, * = Both

2.0.0.0/8          *[BGP/170] 00:00:54, MED 0, localpref 100
                      AS path: 100 ?
                    > to 192.168.11.1 via em0.0
3.0.0.0/8          *[BGP/170] 00:00:54, MED 0, localpref 100
                      AS path: 100 ?
[edit]
root# run show bgp summary
Groups: 2 Peers: 2 Down peers: 0
Table          Tot Paths  Act Paths Suppressed    History Damp State    Pending
inet.0       96         95          0          0          0          0
Peer           AS      InPkt  OutPkt OutQ  Flaps Last Up/Dwn State|#Active/Received/Accepted/Damped...
20.20.20.20    200     3259   4449    0      2    23:29:32 0/0/0/0           0/0/0/0
192.168.11.1   100       12      9    0    734     1:21 95/96/96/0           0/0/0/0

We can see from the BGP summary that we have learnt 1 less route and we don’t have the 1.0.0.0/8 and the default route in our routing table.

now lets add this back and set up a policy to send our default to our ospf neighbours.

root# show policy-options policy-statement OSPF_Default
term 1 {
    from {
        route-filter 0.0.0.0/0 exact;
    }
    then accept;
}
[edit]
root# show protocols ospf
export OSPF_Default;

now lets verify if this.

root# run show route

inet.0: 157 destinations, 158 routes (157 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

0.0.0.0/0          *[Aggregate/130] 01:14:24
                    > to 192.168.11.1 via em0.0
1.0.0.0/8          *[BGP/170] 00:00:33, MED 0, localpref 100
                      AS path: 100 ?
                    > to 192.168.11.1 via em0.0
2.0.0.0/8          *[BGP/170] 00:00:33, MED 0, localpref 100
                      AS path: 100 ?
                    > to 192.168.11.1 via em0.0
3.0.0.0/8          *[BGP/170] 00:00:33, MED 0, localpref 100
                      AS path: 100 ?
                    > to 192.168.11.1 via em0.0
[edit]
root@Router2# run show ospf neighbor
Address      Interface      State     ID               Pri  Dead
10.1.12.1    em0.0          Full      10.10.10.10      128    37
10.1.23.3    em1.0          Full      30.30.30.30      128    32

[edit]
root@Router2# run show route

inet.0: 60 destinations, 60 routes (60 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

0.0.0.0/0          *[OSPF/150] 00:00:08, metric 0, tag 0
                    > to 10.1.12.1 via em0.0
[edit]
root@Router2# run show route 192.168.11.1

inet.0: 60 destinations, 60 routes (60 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

0.0.0.0/0          *[OSPF/150] 00:00:06, metric 0, tag 0
                    > to 10.1.12.1 via em0.0

[edit]
root@Router2# run ping 192.168.11.1 rapid
PING 192.168.11.1 (192.168.11.1): 56 data bytes
!!!!!
--- 192.168.11.1 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 2.574/4.225/8.155/2.029 ms

We have now set up a conditional default route using OSPF.