BGP Next Hop Attribute [Explained and Manipulation Example]
What is BGP Next Hop
The BGP next hop attribute is the next hop IP address that is going to be used to reach a certain destination. It’s a Mandatory well know Attribute. For EBGP, the next hop is always the IP address of the neighbor specified in the neighbor command.
The next-hop attribute for a route depends on which router announces it:
- eBGP: When a router passes route information to a peer in a different AS (using eBGP), it will generally update the next-hop attribute with its own IP address.
- iBGP: However, by default iBGP peers will not change this attribute. For internal routes, the next-hop attribute will be the IP address of the router that sourced the internal route into BGP.
BGP Next Hop Self Configuration Example
So, by default, iBGP won’t change the Next Hop attributes, which can cause the next hop to be unreachable, in order to resolve this issue, we use the Next Hop Self feature.
The next-hop-self command will allow us to force BGP to use its iBGP peer as the Next Hop address rather than letting the protocol choose the next-hop.
Let’s take the previous example and apply next-hop-self on R1:
R1#
router bgp 300
neighbor 1.1.3.2 remote-as 300
neighbor 1.1.3.2 next-hop-self
In simple words, R1 is telling his BGP peer (neighbor) to use him as the next hop, therefore, BGP updates from R1 to R2 will have the Next Hop attribute set to R1 (1.1.3.1).
Notes
* When set ip next-hop is used with the peer-address keyword in an inbound route map of a BGP peer, the next hop of the received matching routes will be set to be the neighbor peering address, overriding any third-party next hops. This means that the same route map can be applied to multiple BGP peers to override third-party next hops.
* When set ip next-hop is used with the peer-address keyword in an outbound route map of a BGP peer, the next hop of the advertised matching routes will be set to be the peering address of the local router, thus disabling the next hop calculation. This command has finer granularity than the per-neighbor neighbor next-hop-self command since you can set the next hop for some routes, but not others. The neighbor next-hop-self sets the next hop for all routes sent to that neighbor
Set a custom BGP Next Hop IP
By using a route map, we can set a custom IP next Hop for a specific BGP peer.
Topology:
The following is an example to be used to illustrate BGP’s next Hop custom modification
Initially, for R1 its Next Hop was R3:
R1#show ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.1/32 0.0.0.0 0 32768 i
*> 5.5.5.5/32 172.16.30.2 0 65001 65001 65003 65005 i
let’s modify the Next Hop to 172.16.45.2:
R1(config)#route-map modif_nh
R1(config-route-map)#set ip next-hop 172.16.45.2
R1(config-route-map)#exit
R1(config)#router bgp 65001
R1(config-router)#neighbor 172.16.30.2 route-map modif_nh in
Verification:
R1#show ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.1/32 0.0.0.0 0 32768 i
* 5.5.5.5/32 172.16.45.2 0 65003 65005 i
*> 172.16.20.2 0 65002 65004 65005 i