BGP Local Preference Attribute Explained in 2024

Rashmi Bhardwaj | Blog,Routing & Switching
Advertisements

What is BGP Local Preference?

The BGP Local Preference attribute is used to manipulate the best outbound path and applied on inbound external routes. Unlike the Weight attribute, Local Preference is passed on to iBGP peers.

If multiple paths exist, Local Preference BGP informs iBGP routers how to exit the AS i.e. which path to prefer for outgoing traffic. Local Preference is a 32-bit number and can range from 0 to 4294967295.

The default preference value is 100. The greater the Local preference e value, the more it becomes the preferred path.

Advertisements

For BGP Path selection algorithm, in case of non-cisco device, the first BGP Path Attribute taken under the consideration is Local Preference attribute. Local Preference is not a vendor dependent Attribute unlike Weight Attribute. Local Preference attribute is used to select external BGP paths. Different edge routers have different Local Preferences to an external destination. These values are sent between IBGP (Interior BGP) neighbors and according to these values, the AS (Autonomous System) exit point is determined.

Local Preference is applied to the inbound direction of the interface. It is the exit point of your AS towards another AS. Different routers have different Local Preference values for that destination and this values is shared within the AS (Autonomous System). LOCAL_PREF is Well-known and Discretionary BGP Path Attribute. LOCAL_PREF is supported in every BGP implementation (well-known) and every BGP router recognizes it but it is optionally present in the BGP Update packet (discretionary).

Some of key features of Local Preference are –

  • Local to an AS.
  • LOCAL_PREF is set to 100 when heard from neighboring AS.
  • Used to influence BGP path selection.
  • Determines best path for outbound traffic.
  • Path with highest local preference wins.

Related  – eBGP vs iBGP

BGP Local preferences can be applied in 2 ways –

1. Directly putting default local preference by iBGP router to its neighbours. Eg –

R3(config)# router bgp 1
R3(config-router)# bgp default local-preference 200

2. On per route basis by calling a Route-map and access/prefix-list through a neighbour. Eg –

R3(config)# ip prefix-list net4 4.4.4.0/24
R3(config)# route-map PREF permit 10
R3(config-route-map)# match ip address prefix-list net4
R3(config-route-map)# set local-preference 300
R3(config)# router bgp 1
R3(config)# neighbour 192.168.35.5 route-map PREF in

Below scenario will help in clarifying how local preference BGP cisco can be configured –

bgp local preferenceRelated- BGP Origin Attribute

As in the above diagram, we are required to have R1 prefer R3 instead of R2 as the best path for reachability to network 4.4.4.0/24 (Loopback of R4).

Related – BGP States

Under the normal case, R1 will receive route for R4 loopback from both iBGP neighbours R2 and R3 .R2 will be the preferred path based on BGP path preference criteria of R2 having lower Router ID ie 192.168.12.2 and R3 with Router ID 192.168.13.3. Below is the snapshot.

snapshot in bgp local preference

Now, we configure the R3 to advertise itself as a preferred path by manipulating the “Local Preference” value as below –

R3(config)# ip prefix-list net4 4.4.4.0/24
R3(config)# route-map PREF permit 10
R3(config-route-map)# match ip address prefix-list net4
R3(config-route-map)# set local-preference 300
R3(config)# router BGP 1
R3(config)# neighbour 192.168.35.5 route-map PREF in

Once the above configuration is performed on R3 and the same information is learned by its iBGP neighbour i.e. R1, the best path for R1 changes from R2 to R3 since R3 has Higher (more preferred) Local preference than R2.

 
bgp-local-preference-attribute

How does BGP choose the best path?

Using the best path selection algorithm, BGP works through each attribute until it finds one to that gives a preference. If there is no preferred attribute BGP will always route over the shortest AS path.

Is Local Preference Transitive?

Local Preference is transitive. It is a Well Known attribute meaning it can be supported by all BGP implementations and all well-known attributes are transitive. Local Preference is not attached to eBGP updates and it only stays within the AS (iBGP).

What is the difference between Weight & LOCAL_PREF in BGP?

The major difference between the Weight and LOCAL_PREF attributes is that when the LOCAL_PREF attribute is applied on router, the change is reflected throughout the AS. On the contrary, Weight attribute is locally significant only.

Below is another lab scenario where BGP Local Preference in manipulated on R2 and R3 (BGP speaking Routers). For reaching network 10.10.100.0/24 (Loopback1 on R1) from R4, the path should be R4-> R3 ->R1. In the same way for reaching network 20.20.200.0/24 (Loopback2 on R1) from R4, the path should be R4-> R2 ->R1. Hence, Local Preference will be advertised from R2 and R3 towards R4, so that R4 takes different paths (based on higher Local preference) to reach networks 10.10.100.0/24 and 20.20.200.0/24 respectively.

Configuration steps to implement Local Preference (on R2 and R3)

  1. An access list will define the network subnet.
  2. A route map can be assigned to the network (ACL) for an action of permit or deny.
  3. The route map action set to the LOCAL_PREF value for the route.
  4. The route map will then be assigned to R3 and R2 against the R4 neighbor, for outbound advertisements.

Below are the configuration steps –

R3(config)#access-list 2 permit 10.10.100.0 0.0.0.255

R3(config)#route-map LOCAL_PREF_200 permit 10

R3(config-route-map) #match ip add 2

R3(config-route-map) #set local-preference 200

R3(config-route-map) #route-map LOCAL_PREF_200 permit 20

R3(config-route-map) #set local-preference 100

R3(config-route-map) #exit

R3(config)#router bgp 200

R3(config-router) #neighbor 1.1.1.1 route-map LOCAL_PREF_200 out

R2(config)#access-list 3 permit 20.20.200.0 0.0.0.255

R2(config)#route-map LOCAL_PREF_200 permit 10

R2(config-route-map) #match ip add 3

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

R2(config-route-map) #route-map LOCAL_PREF_200 permit 20

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

R2(config-route-map) #exit

R2(config)#router bgp 200

R2(config-router) #neighbor 1.1.1.1 route-map LOCAL_PREF_200 out

Conclusion

We understood that BGP path can be manipulated via Local Preference attribute, with higher value of Local Preference being favored compared to lower value.

Continue Reading:

 BGP Interview Questions

BGP Allowas in

ABOUT THE AUTHOR


Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart