Useful command of the week: next-hop-self.
What it is?
Next-hop-self is a BGP router subcommand that is associated with a neighbour. It causes the next hop field for all routes sent to that router to be overwritten with a local address.
Why would you use it?
In short: if the next-hop address is unreachable from your iBGP neighbours.
BGP will not install any routes which has a unreachable next-hop address. A scenario can occur where you form a eBGP relationship on a link that is not advertised within your IGP/to your iBGP peers.
If you overwrite the next-hop address with a local address then this should fix the problem. Basically saying “trust me, I’ll get ya there”
Example
Suppose we have this setup:
As you can see, Thor and Njord will form an eBGP link and Odin and Thor will form an iBGP link.
Here are the IP addresses for reference:
Odin(config-if)#do show ip int brief Interface IP-Address OK? Method Status Protocol FastEthernet0/0 unassigned YES unset up up FastEthernet0/1 10.0.0.1 YES manual up up Loopback0 192.168.0.1 YES manual up up
Thor(config)#do show ip int brief Interface IP-Address OK? Method Status Protocol FastEthernet0/0 10.0.0.2 YES manual up up FastEthernet0/1 10.0.0.5 YES manual up up Loopback0 192.168.0.2 YES manual up up
Njord(config)#do show ip int brief Interface IP-Address OK? Method Status Protocol FastEthernet0/0 10.0.0.6 YES manual up up FastEthernet0/1 unassigned YES unset up up Loopback0 192.168.0.3 YES manual up up
And BGP neighborships have been formed:
Odin#show ip bgp sum Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.0.0.2 4 65000 4 3 1 0 0 00:00:54 1
Thor#show ip bgp sum Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.0.0.1 4 65000 22 25 2 0 0 00:19:30 0 10.0.0.6 4 64900 24 23 2 0 0 00:20:12 1
Njord#show ip bgp sum Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.0.0.5 4 65000 23 24 2 0 0 00:20:34 0
But when you advertise Lo0 on Njord you can see it appears in the BGP tables for Odin and Thor, but only appears in the routing table on Thor.
Njord(config)#router bgp 64900 Njord(config-router)#network 192.168.0.3 mask 255.255.255.255
Thor#show ip bgp BGP table version is 2, local router ID is 192.168.0.2 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 192.168.0.3/32 10.0.0.6 0 0 64900 i
Thor#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
10.0.0.0/30 is subnetted, 2 subnets
C 10.0.0.0 is directly connected, FastEthernet0/0
C 10.0.0.4 is directly connected, FastEthernet0/1
192.168.0.0/32 is subnetted, 2 subnets
C 192.168.0.2 is directly connected, Loopback0
B 192.168.0.3 [20/0] via 10.0.0.6, 00:21:46
Odin#show ip bgp
BGP table version is 3, local router ID is 192.168.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* i192.168.0.3/32 10.0.0.6 0 100 0 64900 i
Odin#show ip route Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route Gateway of last resort is not set 10.0.0.0/30 is subnetted, 1 subnets C 10.0.0.0 is directly connected, FastEthernet0/1 192.168.0.0/32 is subnetted, 1 subnets C 192.168.0.1 is directly connected, Loopback0
You add the next-hop-self command on Thor (the eBGP/iBGP border router) for the Odin neighborship:
Thor#conf t Enter configuration commands, one per line. End with CNTL/Z. Thor(config)#router bgp 65000 Thor(config-router)#neighbor 10.0.0.1 next-hop-self
Then you will see the route come through on Odin, notice also the next-hop attribute in the BGP table:
Odin#show ip bgp
BGP table version is 4, local router ID is 192.168.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i192.168.0.3/32 10.0.0.2 0 100 0 64900 i
Odin#show ip route Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route Gateway of last resort is not set 10.0.0.0/30 is subnetted, 1 subnets C 10.0.0.0 is directly connected, FastEthernet0/1 192.168.0.0/32 is subnetted, 2 subnets C 192.168.0.1 is directly connected, Loopback0 B 192.168.0.3 [200/0] via 10.0.0.2, 00:00:49
And that’s next-hop-self and when to use it.