BGP next-hop attribute: the IP address that should be used as the next-hop to the destinations listed in the Update message.
The next-hop attribute is a well-known mandatory attribute. The next-hop attribute is calculated differently for IBGP and EBGP.
When a route is advertised across an EBGP sessions, the IP address that is propagated as next-hop is changed. The value it changes to is the advertising router’s IP address that is used to setup the BGP session.
When a route is advertised across an IBGP session, the IP address that is propagated as next-hop should not change, unless the router is configured to do so.
In the picture above, I have tried to visualize the difference between IBGP and EBGP by using an example route x. When originally sourced from AS1, the next-hop is set to R1’s address used for the BGP session with R2. When R2 communicated the route to R3 or R4 (across an IBGP session), the next-hop remains the same. When route x leaves AS2 across the EBGP session between R4 and R5, the next-hop is updated to 10.0.0.1, R4’s address used to maintain the BGP session with R5.
When a route is received from an another AS, like in the example, IBGP will not alter the next-hop attribute. However, what if the route is sourced by an IBGP speaking router? In case a route is originated from within an AS and advertised across an IBGP session, there are two possible scenarios.
The first scenario is when a route has a forwarding next-hop. In this case, the next-hop is set to the forwarding address.
In the picture above, the route 10.0.0.0/29 has a forwarding address of 192.168.1.1. In this example, the next-hop in the Update message between IBGP peers R2 and R3 will be set to 192.168.1.1.
The second scenario is when a route does not have a forwarding address. This can be the case when a static route uses a next-hop address of discard or reject. In these cases, the next-hop IP address that is communicated in the Update message will be the IP address used for the BGP session.
In the picture above, R2 is using 18.104.22.168 as source IP for an IBGP session with R3. R2 is also redistributing a static route without a forwarding address into BGP. The next-hop that the route will have in the Update message to R3 will be 22.214.171.124.