BGP next hop self explained

BGP next hop is a mandatory attribute of BPG which provide information of the next hop for the advertised subnet. iBGP doesn’t change the next hop of advertised subnets. BGP next hop self can help in changing the next hop of advertised subnets in IBGP.

Let’s understand the why we need BGP next hop self. Consider below topology we have total 7 routers and 4 unique ASN. There is iBGP running in AS4567, EBGP is running between rest of the routers. Without next-hop-self Router7 will not be able to reach subnet 1.1.1.1.

bpg next hop self

Now we will advertise loopback 0 subnet from router 1 towards its neighbors Router2 and Router3.

R1#show run | sec bgp
router bgp 1
 bgp log-neighbor-changes
 network 1.1.1.1 mask 255.255.255.255
 network 10.12.12.0 mask 255.255.255.0
 network 10.13.13.0 mask 255.255.255.0
 neighbor 10.12.12.2 remote-as 2
 neighbor 10.13.13.3 remote-as 3
 network 1.1.1.1 mask 255.255.255.255

Let’s validate on Router2 and Router3 if they have received the route. We can validate the routes using command “show ip bgp“.

R2#show run | sec bgp
router bgp 2
 bgp log-neighbor-changes
 network 10.12.12.0 mask 255.255.255.0
 network 10.24.24.0 mask 255.255.255.0
 neighbor 4.4.4.4 remote-as 4567
 neighbor 4.4.4.4 ebgp-multihop 2
 neighbor 4.4.4.4 update-source Loopback0
 neighbor 10.12.12.1 remote-as 1

R2#show ip bgp
BGP table version is 10, local router ID is 22.22.22.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,
              t secondary path, L long-lived-stale,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>   1.1.1.1/32       10.12.12.1              0             0 1 i

=================================================================

R3#show run | sec bgp
router bgp 3
 bgp log-neighbor-changes
 network 10.13.13.0 mask 255.255.255.0
 network 10.35.35.0 mask 255.255.255.0
 neighbor 10.13.13.1 remote-as 1
 neighbor 10.35.35.5 remote-as 4567

R3#show ip bgp
BGP table version is 17, local router ID is 3.3.3.3
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,
              t secondary path, L long-lived-stale,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>   1.1.1.1/32       10.13.13.1              0             0 1 i

Now lets check on Router4 we can see the routes are learned and inserted into routing table. There are two paths to the network one from Router2 and another one from router3.

R4#show ip bgp
BGP table version is 14, local router ID is 4.4.4.4
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,
              t secondary path, L long-lived-stale,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 * i  1.1.1.1/32       10.35.35.3              0    100      0 3 1 i
 *>                    2.2.2.2                               0 2 1 i

R4#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 13
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     2          3
  Refresh Epoch 1
  3 1
    10.35.35.3 (inaccessible) from 5.5.5.5 (5.5.5.5)
      Origin IGP, metric 0, localpref 100, valid, internal
      rx pathid: 0, tx pathid: 0
      Updated on Jan 1 2024 09:44:33 UTC
  Refresh Epoch 1
  2 1
    2.2.2.2 from 2.2.2.2 (22.22.22.1)
      Origin IGP, localpref 100, valid, external, best
      rx pathid: 0, tx pathid: 0x0
      Updated on Jan 1 2024 08:44:35 UTC


R4#show ip route
Codes: L - local, 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, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       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
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
B        1.1.1.1 [20/0] via 2.2.2.2, 01:03:55

Now when we check on Router 7 we will see that route is not in the routing table however it is present in the BGP table. Notice the next hop IP address of the routes, Its the IP address advertised by the Router2 and Router3. As Router7 doesn’t know how to reach the Next hop so it doesn’t add the route into the routing table. If we check command “show ip bgp 1.1.1.1” it says no best path.

R7#show ip bgp
BGP table version is 4, local router ID is 7.7.7.7
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,
              t secondary path, L long-lived-stale,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 * i  1.1.1.1/32       10.35.35.3              0    100      0 3 1 i
 * i                   2.2.2.2                 0    100      0 2 1 i

R7#show ip route
Codes: L - local, 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, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       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
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      4.0.0.0/32 is subnetted, 1 subnets
O        4.4.4.4 [110/2] via 10.45.67.4, 16:06:22, GigabitEthernet4
      5.0.0.0/32 is subnetted, 1 subnets

R7#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 0
Paths: (2 available, no best path)
  Not advertised to any peer
  Refresh Epoch 1
  3 1
    10.35.35.3 (inaccessible) from 5.5.5.5 (5.5.5.5)
      Origin IGP, metric 0, localpref 100, valid, internal
      rx pathid: 0, tx pathid: 0
      Updated on Jan 1 2024 08:44:35 UTC
  Refresh Epoch 1
  2 1
    2.2.2.2 (inaccessible) from 4.4.4.4 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, internal
      rx pathid: 0, tx pathid: 0
      Updated on Jan 1 2024 08:44:35 UTC
R7#

Adding static route or by having IGP or with the next of next-hop-self command we can solve this problem.

For this example we will use next-hop-self

R4(config)#router bgp 4567
R4(config-router)#neighbor 7.7.7.7 next-hop-self

R5(config)#router bgp 4567
R5(config-router)#neighbor 7.7.7.7 next-hop-self

Looking at router7 now will show the route have best path and is present in the routing table.

R7#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 8
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     2
  Refresh Epoch 2
  3 1
    5.5.5.5 (metric 2) from 5.5.5.5 (5.5.5.5)
      Origin IGP, metric 0, localpref 100, valid, internal
      rx pathid: 0, tx pathid: 0
      Updated on Jan 1 2024 09:27:24 UTC
  Refresh Epoch 1
  2 1
    4.4.4.4 (metric 2) from 4.4.4.4 (4.4.4.4)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      rx pathid: 0, tx pathid: 0x0
      Updated on Jan 1 2024 09:27:48 UTC
R7#

R7#show ip route
Codes: L - local, 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, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       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
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
B        1.1.1.1 [200/0] via 4.4.4.4, 00:02:11

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.