top of page

BGP Local Preference

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 6.6.6.6/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 6.6.6.6

​

R2#sh ip bgp

​

BGP table version is 15, local router ID is 10.0.12.2

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete

 

Network          Next Hop            Metric LocPrf Weight Path

*  6.6.6.6/32       10.0.24.4                                            0 65504 65505 65506 i

*>                       10.0.23.3                                            0 65503 65506 i

* i10.0.12.0/24     10.0.12.1                0    100      0 i

*>                  0.0.0.0                  0         32768 i

*  10.0.23.0/24     10.0.23.3                0             0 65503 i

*>                  0.0.0.0                  0         32768 i

*  10.0.24.0/24     10.0.24.4                0             0 65504 i

*>                  0.0.0.0                  0         32768 i

*> 10.0.36.0/24     10.0.23.3                0             0 65503 i

*> 10.0.45.0/24     10.0.24.4                0             0 65504 i

*  10.0.56.0/24     10.0.23.3                              0 65503 65506 i

*>                  10.0.24.4                              0 65504 65505 i

​

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 6.6.6.6 as it has a higher local preference.

​

To set this we will configure a route map on connection to R4 inbound as below

​

R2(config-router)#neighbor 10.0.24.4 route-map LOCAL-PREF-150 in

R2(config-router)#route-map LOCAL-PREF-150

R2(config-route-map)#set local-preference 150

​

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 *

​

R2#clear ip bgp *

R2#

*Mar  1 01:21:08.847: %BGP-5-ADJCHANGE: neighbor 10.0.12.1 Down User reset

*Mar  1 01:21:08.847: %BGP-5-ADJCHANGE: neighbor 10.0.23.3 Down User reset

*Mar  1 01:21:08.851: %BGP-5-ADJCHANGE: neighbor 10.0.24.4 Down User reset

​

R2#

*Mar  1 01:21:22.607: %BGP-5-ADJCHANGE: neighbor 10.0.23.3 Up

*Mar  1 01:21:22.611: %BGP-5-ADJCHANGE: neighbor 10.0.24.4 Up

*Mar  1 01:21:22.627: %BGP-5-ADJCHANGE: neighbor 10.0.12.1 Up

​

There is a much better method to perform the route-refresh is to do a soft reset as below

​

R2#clear ip bgp 10.0.24.4 soft

​

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?

​

R2#sh ip bgp

​

BGP table version is 22, local router ID is 10.0.24.2

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete

 

   Network          Next Hop            Metric LocPrf Weight Path

*> 6.6.6.6/32       10.0.24.4                     150      0 65504 65505 65506 i

*                   10.0.23.3                              0 65503 65506 i

*> 10.0.12.0/24     0.0.0.0                  0         32768 i

* i                 10.0.12.1                0    100      0 i

*> 10.0.23.0/24     0.0.0.0                  0         32768 i

*                   10.0.23.3                0             0 65503 i

*> 10.0.24.0/24     0.0.0.0                  0         32768 i

*                   10.0.24.4                0    150      0 65504 i

*> 10.0.36.0/24     10.0.24.4                     150      0 65504 65505 65506 i

*                   10.0.23.3                0             0 65503 i

*> 10.0.45.0/24     10.0.24.4                0    150      0 65504 i

*                   10.0.23.3                              0 65503 65506 65505 i

*> 10.0.56.0/24     10.0.24.4                     150      0 65504 65505 i

*                   10.0.23.3                              0 65503 65506 i

​

As you can see the route for 6.6.6.6/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

​

R1#sh ip bgp

​

BGP table version is 35, local router ID is 10.0.12.1

​

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete

 

   Network          Next Hop            Metric LocPrf Weight Path

*>i6.6.6.6/32       10.0.24.4                0    150      0 65504 65505 65506 i

* i10.0.12.0/24     10.0.12.2                0    100      0 i

*>                  0.0.0.0                  0         32768 i

*>i10.0.23.0/24     10.0.12.2                0    100      0 i

*>i10.0.24.0/24     10.0.12.2                0    100      0 i

*>i10.0.36.0/24     10.0.24.4                0    150      0 65504 65505 65506 i

*>i10.0.45.0/24     10.0.24.4                0    150      0 65504 i

*>i10.0.56.0/24     10.0.24.4                0    150      0 65504 65505 i

​

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 6.6.6.6 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

​

# ip prefix-list 6-6-6-6 seq 5 permit 6.6.6.6/32

 

# route-map LOCAL-PREF-150 permit 10

# match ip address prefix-list 6-6-6-6

# set local-preference 150

​

If we then do a soft reset and check the sh ip bgp output again you will see that it is only affecting the 6.6.6.6 network

​

R2#sh ip bgp

​

BGP table version is 25, local router ID is 10.0.24.2

​

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

              r RIB-failure, S Stale

Origin codes: i - IGP, e - EGP, ? - incomplete

 

   Network          Next Hop            Metric LocPrf Weight Path

*> 6.6.6.6/32       10.0.24.4                     150      0 65504 65505 65506 i

*                   10.0.23.3                              0 65503 65506 i

*> 10.0.12.0/24     0.0.0.0                  0         32768 i

* i                 10.0.12.1                0    100      0 i

*> 10.0.23.0/24     0.0.0.0                  0         32768 i

*                   10.0.23.3                0             0 65503 i

*> 10.0.24.0/24     0.0.0.0                  0         32768 i

*> 10.0.36.0/24     10.0.23.3                0             0 65503 i

*> 10.0.45.0/24     10.0.23.3                              0 65503 65506 65505 i

*> 10.0.56.0/24     10.0.23.3                              0 65503 65506 i

​

We can verify this is working with a trace showing the path to 6.6.6.6 is via 10.0.24.4 (R4)

​

R2#trace 6.6.6.6

 

Type escape sequence to abort.

Tracing the route to 6.6.6.6

 

  1 10.0.24.4 72 msec 84 msec 32 msec

  2 10.0.45.5 [AS 65505] 64 msec 64 msec 68 msec

  3 10.0.56.6 [AS 65506] 68 msec *  184 msec

bottom of page