The BGP Local Preference attribute or local-pref is used to influence the outbound routing decision of a router running BGP.
The local preference has to be set in bound on routes being received to influence the outbound routing behaviour. A higher local preference is preferred and the default is 100.
For this BGP tutorial I will be using the simple topology below. The route 126.96.36.199/32 is being learned via R6 and we are going to try to influence the routing decision on R2 to take the path via the longer AS path through R4 and R5. All routers are addressed with the interface ip relevant to the router. e.g all R2’s ip addresses will end with .2
As you remember from your BGP studies the BGP best path algorithm states that if local preference is the same then the path with the shortest AS path will be chosen. As local preference is higher up the decision process if we can change that we can influence the routing over the shortest AS-path choice.
Lets take a look at the routing on R2 and the path it is currently choosing to get to 188.8.131.52
So as you can see R2 is preferring the path via R3 as indicated by the > symbol, you can also see that there are two paths available, but the path through R4 is via a longer AS path. We are now going to change the routing behaviour by setting the Local Preference of all routes coming in via R4 higher. This will mean R2 will decide to route to R4 to get to 184.108.40.206 as it has a higher local preference.
To set this we will configure a route map on connection to R4 inbound as below
After you make this change it’s best to clear the process, as this is a lab environment it is safe to just do clear ip bgp *
There is a much better method to perform the route-refresh is to do a soft reset as below
This keeps the tcp session up and just refreshes any routing changes.
So lets see if our route-map changing the bgp local preference has made any difference?
As you can see the route for 220.127.116.11/32 now has the > by the path via 10.0.24.4 (R4) and the local preference is showing as 150 this means it is taking a longer AS path but as local preference is higher up the bgp algorithm it is chosen first as the routing decision.
One last point is that the local-preference value is passed between iBGP neighbors but it is not passed between eBGP neighbors. So if we look on R1 you will see the bgp local preference value as 150
There is one more thing we can do and that is get a bit more specific. As you can see the local preference attribute has been applied to all routes coming in from R4, if we just wanted to do it for 18.104.22.168 then we could match this network in a prefix-list and add that to the route-map.
First I need to create a prefix-list and then match it in the route-map
If we then do a soft reset and check the sh ip bgp output again you will see that it is only affecting the 22.214.171.124 network
We can verify this is working with a trace showing the path to 126.96.36.199 is via 10.0.24.4 (R4)