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 ie 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.
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 –
2. On per route basis by calling a Route-map and access/prefix-list through a neighbour. Eg –
Below scenario will help in clarifying how local preference BGP cisco can be configured –
Related- 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 126.96.36.199/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.
Now, we configure the R3 to advertise itself as a preferred path by manipulating the “Local Preference” value as below –
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.
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 188.8.131.52/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 184.108.40.206/24 respectively.
Configuration steps to implement Local Preference (on R2 and R3)
- An access list will define the network subnet.
- A route map can be assigned to the network (ACL) for an action of permit or deny.
- The route map action set to the LOCAL_PREF value for the route.
- The route map will then be assigned to R3 and R2 against the R4 neighbor, for outbound advertisements.
Below are the configuration steps –
We understood that BGP path can be manipulated via Local Preference attribute, with higher value of Local Preference being favored compared to lower value.
Related – BGP Interview Questions
Related- BGP Allowas in