Tuesday, May 19, 2015

Configuring BGP - Advertising default route to neighbors - default originate

This post is dedicated to my good friend / colleague Mr. Rage :) 

In this blogtorial we will explore one of the methods by which we can advertise a default route to BGP neighbors. One of my colleagues last week asked "would we loose the BGP default route advertisement if the advertising neighbor lost the default route in its own RIB" and honestly I wasn't sure. And I hate being unsure of "something" network related. So I did what any curious person would do, I lab'd it up and it turns out that default route advertisement is not lost when you loose the default route in the routing table, although you can certainly configure it as such.

Here is a simple topology to get started. 




Let's get our base configuration done ...

 R1#sh run int gig1.12  
 !  
 interface GigabitEthernet1.12  
  encapsulation dot1Q 12  
  ip address 12.12.12.1 255.255.255.0  
 end  

 R1#sh run | in ip route  
 ip route 0.0.0.0 0.0.0.0 Null0  

  
 R1#sh run | sec bgp  
 router bgp 1  
  bgp log-neighbor-changes  
  neighbor 12.12.12.2 remote-as 2  
  neighbor 12.12.12.2 default-originate  

 R2#sh run int gig1.12  
 Building configuration...  
 Current configuration : 98 bytes  
 !  
 interface GigabitEthernet1.12  
  encapsulation dot1Q 12  
  ip address 12.12.12.2 255.255.255.0  
 end  


 R2#sh run | sec bgp  
 router bgp 2  
  bgp log-neighbor-changes  
  neighbor 12.12.12.1 remote-as 1  


 R2#sh ip bgp     
 BGP table version is 2, local router ID is 150.1.2.2  
 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,   
        r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,   
        x best-external, a additional-path, c RIB-compressed,   
 Origin codes: i - IGP, e - EGP, ? - incomplete  
 RPKI validation codes: V valid, I invalid, N Not found  
    Network     Next Hop      Metric LocPrf Weight Path  
  *> 0.0.0.0     12.12.12.1               0 1 i  

 R2#sh ip route 0.0.0.0   
 Routing entry for 0.0.0.0/0, supernet  
  Known via "bgp 2", distance 20, metric 0, candidate default path  
  Tag 1, type external  
  Last update from 12.12.12.1 00:03:39 ago  
  Routing Descriptor Blocks:  
  * 12.12.12.1, from 12.12.12.1, 00:03:39 ago  
    Route metric is 0, traffic share count is 1  
    AS Hops 1  
    Route tag 1  
    MPLS label: none  

At this point, we have an eBGP peering between R1 and R2. R1 has a default route pointing to null0 in its routing table. R1 is advertising a default route to R2 and as a result R2 has a default route in its RIB.

Now let's take out the default route from R1's RIB and see if R1 is still advertising a default route to R2.

 R1(config)#  
 %SYS-5-CONFIG_I: Configured from console by console  
 R1(config)#no ip route 0.0.0.0 0.0.0.0 null0  
 R1(config)#exit  

 R1#clear ip bgp *  
 R1#  
 %BGP-3-NOTIFICATION_ALL: sent to all sessions 6/4 (Administrative Reset)  
 R1#  
 %BGP-5-ADJCHANGE: neighbor 12.12.12.2 Down User reset  
 %BGP_SESSION-5-ADJCHANGE: neighbor 12.12.12.2 IPv4 Unicast topology base removed from session

 R1#show ip bgp nei 12.12.12.2 advertised-routes   
 BGP table version is 3, local router ID is 150.1.1.1  
 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,   
        r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,   
        x best-external, a additional-path, c RIB-compressed,   
 Origin codes: i - IGP, e - EGP, ? - incomplete  
 RPKI validation codes: V valid, I invalid, N Not found  
 Originating default network 0.0.0.0  
    Network     Next Hop      Metric LocPrf Weight Path  
 Total number of prefixes 0   

As you can see even though there is no default in R1's RIB, default route is still being advertised to R2.

So what if you wanted to withdraw the default advertisement to R2 when R1 looses the default in its RIB?

You can actually do conditional default advertisement based on if you had a specific prefix in the routing table by using a route-map attached to default-originate command. This means that whatever you are matching with the route-map has to exist in the RIB in order for the default route to be advertised to the neighbor.

 R1#conf t  
 R1(config)#ip prefix-list match_default seq 10 permit 0.0.0.0/0  
 R1(config)#route-map match_default permit 10  
 R1(config-route-map)#match ip add prefix-list match_default  
 R1(config-route-map)#exit  
 R1(config)#router bgp 1  
 R1(config-router)#nei 12.12.12.2 default-originate route-map match_default   
 R1(config-router)#exit  
 R1(config)#exit  
!
 R1#sh run | sec bgp  
 router bgp 1  
  bgp log-neighbor-changes  
  neighbor 12.12.12.2 remote-as 2  
  neighbor 12.12.12.2 default-originate route-map match_default  
!
 R1#sh ip route 0.0.0.0   
 % Network not in table  
!
 R1#sh ip bgp nei 12.12.12.2 advertised-routes   
 Total number of prefixes 0   
!

Notice that since there is no default in the RIB on R1, no routes are being advertised.

Let's add the default route back into R1 RIB and check out the advertisement to R2.

 R1#conf t  
 R1(config)#ip route 0.0.0.0 0.0.0.0 null0  
 R1(config)#^Z  
!
 R1#sh ip bgp nei 12.12.12.2 advertised-routes   
 BGP table version is 4, local router ID is 150.1.1.1  
 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,   
        r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,   
        x best-external, a additional-path, c RIB-compressed,   
 Origin codes: i - IGP, e - EGP, ? - incomplete  
 RPKI validation codes: V valid, I invalid, N Not found  
 Originating default network 0.0.0.0  
    Network     Next Hop      Metric LocPrf Weight Path  
 Total number of prefixes 0   

Many more articles to come so ....

Please subscribe/comment/+1 if you like my posts as it keeps me motivated to write more and spread the knowledge.

"When you find yourself to be the smartest one in the room, then it is time to leave the room" 

No comments:

Post a Comment