BGP when to use next-hop-self

When implementing BGP, the next-hop-self keyword is added to the neighbor command to change the next hop IP address for a particular prefix to the router itself.

The next-hop-self command is typically used by an eBGP router when advertising a route it learned from its eBGP neighbor to its iBGP peers.

Why does it do this? Because if it does not, the next-hop IP will be the IP address of the eBGP peer, which is in another AS, thus its IP address is unknown within the local AS. The next-hop for that prefix thus be replaced with the IP address of the eBGP router connecting to that foreign AS.