BGP Local Preference (LOCAL_PREF)

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
atech_R1(config)#router bgp 100
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
atech_R2(config)#router bgp 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 remote-as 200
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_R2(config-router)#neighbor 12.12.12.1 remote-as 100

 

atech_R3
atech_R3(config)#router bgp 200
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 remote-as 200
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)#neighbor 13.13.13.1 remote-as 100

 

 

atech_R4
atech_R4(config)#router bgp 200
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 remote-as 200
atech_R4(config-router)#neighbor 3.3.3.3 update-source Loopback0
atech_R4(config-router)#neighbor 3.3.3.3 next-hop-self
atech_R4(config-router)#network  4.4.4.4 mask 255.255.255.255

 

Now, if we check the route at R1:

atech_R1#sh ip bgp
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
Network        Next Hop     Metric   LocPrf     Weight     Path
*>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 200
atech_R2(config-router)#bgp default local-preference 200

 

atech_R1#sh ip bgp
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.

 

 

*Note
There is already IGP(OSPF) in AS200 which is required for iBGP. I have not showed the OSPF configuration here so that readers can focus & grip the topic under discussion i.e. LOCAL_PREF. This is OSPF configuration if you want to simulate the same lab yourself

 

R2
atech_R2(config)#router ospf 1
atech_R2(config-router)#router-id 2.2.2.2
atech_R2(config-router)#interface range Lo0, Fa0/0, Fa1/0
atech_R2(config-router)#ip ospf 1 area 0
R3
atech_R3(config)#router ospf 1
atech_R3(config-router)#router-id 3.3.3.3
atech_R3(config-router)#interface range Lo0, Fa0/1, Fa1/0
atech_R3(config-router)#ip ospf 1 area 0
R4
atech_R4(config)#router ospf 1
atech_R4(config-router)#router-id 4.4.4.4
atech_R4(config-router)#interface range Lo0, Fa0/0, Fa0/1
atech_R4(config-router)#ip ospf 1 area 0

 

*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…

 

 

 

Written by 

Waqas Karim is a seasoned Network Expert … Geek. He is the founder of ATech. ATech was started for learning & sharing. Over time the platform has grown to include other resources which continue to attract fellow networkers. Today it sees upward trend of a hundred thousand visitors per month, scattered all over the globe. His specialty is networking, but his interest & expertise spans from traditional IT to Network Security including Programming, Virtualization, Service Provider & so on... no matter the badge on the box. He is CCIE Certified (CCIE#56732) in addition to below badges: Telecom Engineer (BE) + CCIE-RS (CCIE#56732) + Huawei Certified (HW#706632) + MBA Microsoft Certified MCITP, MCSE#109*26, CCNP-Sec, CCNP-SP, CCNA-DC, CompTIA Security+, Nokia NRS-I, JNCIA, ITIL Certified (ITIL#*6373), CEH (Certified Ethical Hacker).

avatar
5 Comment threads
7 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
7 Comment authors
Willow AbigailJuanaWaqas KarimJuanaMabel.Raquel52422@outlook.com Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Juana
Guest
Juana

Do we need to clear the bgp process if we change the LP?

Mabel.Raquel52422@outlook.com
Guest
Mabel.Raquel52422@outlook.com

Is BGP Local Preference shared with all Routers in the local AS or it is only for other AS’s?

Deri98677@Ymail.com
Guest
Deri98677@Ymail.com

Can you plz share the Weight configuration as well so that I can compare it with this Local Preference configuration….?

Esmanur Elanur
Guest
Esmanur Elanur

Nice article!!!!!

Willow Abigail
Guest
Willow Abigail

How is LOCAL_PREF diff from MED & Weight?