BGP LOCAL_PREF is the Second BGP attribute if we dive deep into BGP’s algorithm of best path selection followed by aggregate (detailed in my first post in BGP section).
When an AS (autonomous system) has multiple routes to another AS, the LOCAL_PREF indicates the degree of preference for one route over the other routes. The route with the highest LOCAL_PREF value is preferred.
You can watch the detailed video on LOCAL_PREF on our YouTube Channel:
LOCAL_PREF, Weight & MED are often confused with each other. LOCAL_PREF is different from Weight & MED. Unlike weight, LOCAL_PREF is not vendor specific (Weight is Cisco proprietary, so it is found only on Cisco routers). LOCAL_PREF is to influence your own AS how to get or exit to another AS while MED is to influence other AS how to enter your AS. Means, LOCAL_PREF is used to influence route selection within the local autonomous system. MED is b/w AS’s while LOCAL_PREF is only for local AS. LOCAL_PREF only affect the traffic leaving the AS.
LOCAL_PREF is always exchanged between iBGP Peers i.e. if we change the LOCAL_PREF on one the router, it is broadcasted to all the iBGP Neighbors in the AS. LOCAL_PREF is never exchanged between eBGP Peers (it is only exchanged between iBGP Peers).
The path with the highest LOCAL_PREF is always preferred.
LOCAL_PREF is a ‘Well-Known Discretionary’ BGP attribute. Well Known means that it must be recognized by all the BGP Routers.
Discretionary means that although LOCAL_PREF is recognized by all BGP Routers in the domain but it may or may not be sent in a specific Update message. Its up to the discretion of BGP Implementation to send or not to send these attributes in the update messages to the peers.
LOCAL_PREF is a 32-bit number. So, it ranges from 0 to 4294967295 (232 – 1). Default LOCAL_PREF value is 100 (if we don’t set any value, all routes/routers have a LOCAL_PREF of 100). If a BGP route is received without a LOCAL_PREF attribute, the route is stored in the routing table and advertised by BGP as if it were received with a LOCAL_PREF value of 100. A non-BGP route that is advertised by BGP is advertised with a LOCAL_PREF value of 100 by default.
LOCAL_PREF is always set on inbound on routes which we receive and it influences the OUTBOUND routing behaviour. We use LOCAL_PREF when we want to influence our BGP routing OUTBOUND on a router.
Let me explain it through a simple example in below.
Configuration Example
There are different methods to set LOCAL_PREF in BGP including Global commands, route maps and so on. We will use Global level command in this example:
Consider below topology. Here we have four Routers. R1 is receiving a route for 4.4.4.4/32 from both R2 & R3.
In normal conditions, it will prefer the route from R3. We can influence this selection by using higher LOCAL_PREF towards R2.
First, lets establish simple BGP as in below:
atech_R1(config-router)#bgp router-id 1.1.1.1
atech_R1(config-router)#bgp log-neighbor-changes
atech_R1(config-router)#neighbor 12.12.12.2 remote-as 200
atech_R1(config-router)#neighbor 13.13.13.3 remote-as 200
atech_R2(config-router)#bgp router-id 2.2.2.2
atech_R2(config-router)#bgp log-neighbor-changes
atech_R2(config-router)#neighbor 3.3.3.3 remote-as 200
atech_R2(config-router)#neighbor 3.3.3.3 update-source Loopback0
atech_R2(config-router)#neighbor 3.3.3.3 next-hop-self
atech_R2(config-router)#neighbor 4.4.4.4 update-source Loopback0
atech_R2(config-router)#neighbor 4.4.4.4 next-hop-self
atech_R3(config-router)#bgp router-id 3.3.3.3
atech_R3(config-router)#bgp log-neighbor-changes
atech_R3(config-router)#neighbor 2.2.2.2 remote-as 200
atech_R3(config-router)#neighbor 2.2.2.2 update-source Loopback0
atech_R3(config-router)#neighbor 2.2.2.2 next-hop-self
atech_R2(config-router)#neighbor 4.4.4.4 update-source Loopback0
atech_R2(config-router)#neighbor 4.4.4.4 next-hop-self
atech_R4(config-router)#bgp router-id 4.4.4.4
atech_R4(config-router)#bgp log-neighbor-changes
atech_R4(config-router)#neighbor 2.2.2.2 remote-as 200
atech_R4(config-router)#neighbor 2.2.2.2 update-source Loopback0
atech_R4(config-router)#neighbor 2.2.2.2 next-hop-self
atech_R4(config-router)#neighbor 3.3.3.3 update-source Loopback0
atech_R4(config-router)#neighbor 3.3.3.3 next-hop-self
Now, if we check the route at R1:
BGP table version is 3, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not found
*>4.4.4.4/32 12.12.12.2 0 200 i
*> 13.13.13.3 0 200 i
We can see that although it is receiving 4.4.4.4/32 route from both R2 & R3 but it is preferring the route from R3 by default.
Now, lets increase LOCAL_PREF on R2:
atech_R2(config-router)#bgp default local-preference 200
BGP table version is 3, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
x best-external, a additional-path, c RIB-compressed,
Origin codes: i – IGP, e – EGP, ? – incomplete
RPKI validation codes: V valid, I invalid, N Not foundNetwork Next Hop Metric LocPrf Weight Path
* 4.4.4.4/32 13.13.13.3 0 200 i
*> 12.12.12.2 0 200 i
As in above, R1 is preferring route from R2 now because it has High LOCAL_PREF as compared to R3. In this way, we can influence the BGP route selection by changing the LOCAL_PREF.
We can achieve the same results by using Route Maps which gives more granularity & control upto prefix level. The route map simply captures all the desired routes & apply it on the neighbor command.
*No OSPF on R1 as it has only eBGP..
You can watch the detailed video on LOCAL_PREF in English or Hindi/Urdu on our YouTube Channel:
I hope this article has been helpful to you. You suggestion, comments & questions are welcomed. Please write in comments below if any…
Do we need to clear the bgp process if we change the LP?
Yes, we need to perform a soft reset i.e. clear the bgp process on the router in order for changes to be taken in to effect. Use the #clear ip bgp soft command
Thanxxx!!!
Is BGP Local Preference shared with all Routers in the local AS or it is only for other AS’s?
Yes, BGP LOCAL-PREF is sent to all internal BGP routers in our Autonomous System
Can you plz share the Weight configuration as well so that I can compare it with this Local Preference configuration….?
Yes, it is in BGP section of ATech. Please follow at: https://aurumme.com/atech/bgp-weight/
There is also a video on my YouTube channel: https://www.youtube.com/watch?v=dTBlE-dDpNk
Nice article!!!!!
Thanks for appr
How is LOCAL_PREF diff from MED & Weight?
LOCAL_PREF is different from Weight & MED. Unlike weight, LOCAL_PREF is not vendor specific (Weight is Cisco proprietary, so it is found only on Cisco routers). LOCAL_PREF is to influence your own AS how to get or exit to another AS while MED is to influence other AS how to enter your AS. Means, LOCAL_PREF is used to influence route selection within the local autonomous system. MED is b/w AS’s while LOCAL_PREF is only for local AS. LOCAL_PREF only affect the traffic leaving the AS.
Thanks for clarification