BGP Local Preference

Local Preference is one of the ways to alter the path taken by one AS to reach another AS. The difference between Local Preference and Weight is that Weight is just locally signifant in the router while Local Preference is what I call "Local AS significant". What I mean by that is that Local Preference is being propagated Intra AS but not outside the AS.


Local preference is to influence your own AS how to get or exit to another AS.
MED is to influence other AS how to enter your AS.
The higher the local preference, the more preferred.

In this lab, local preference will be configured and will be using route map for more flexibility. Check the diagram below for details.
R1, R2 and R3 belongs to AS 123. R4 is in AS4 and is advertising 4.4.4.4/32, 44.44.44.44/32 and 144.144.144.144/32
subnets.We need to set all routes learned from R3 to have local preference value of 300. After which, configure a
route-map that will assign a local preference of 500 in R2 for the network 144.144.144.144/32.

Here are the initial BGP configurations on the routers.


R1#
!
router bgp 123
no synchronization
bgp log-neighbor-changes
neighbor 12.12.12.2 remote-as 123
neighbor 13.13.13.3 remote-as 123
no auto-summary

R2#
!
router bgp 123
no synchronization
bgp log-neighbor-changes
neighbor 12.12.12.1 remote-as 123
neighbor 12.12.12.1 next-hop-self
neighbor 24.24.24.4 remote-as 4
no auto-summary

R3#
!
router bgp 123
no synchronization
bgp log-neighbor-changes
neighbor 13.13.13.1 remote-as 123
neighbor 13.13.13.1 next-hop-self
neighbor 34.34.34.4 remote-as 4
no auto-summary

R4#
!
router bgp 4
no synchronization
bgp log-neighbor-changes
network 4.4.4.4 mask 255.255.255.255
network 44.44.44.44 mask 255.255.255.255
network 144.144.144.144 mask 255.255.255.255
neighbor 24.24.24.2 remote-as 123
neighbor 34.34.34.3 remote-as 123
no auto-summary

Let's see what is the best path taken by R1 to reach the networks advertised by R4.


R1#sh ip bgp

BGP table version is 10, 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
Origin codes: i - IGP, e - EGP, ? - incomplete

Network Next Hop Metric LocPrf Weight Path
*>i4.4.4.4/32 12.12.12.2 0 100 0 4 i
* i 13.13.13.3 0 100 0 4 i
*>i44.44.44.44/32 12.12.12.2 0 100 0 4 i
* i 13.13.13.3 0 100 0 4 i
*>i144.144.144.144/32
12.12.12.2 0 100 0 4 i
* i 13.13.13.3 0 100 0 4 i

R1#sh ip route | beg Gateway


Gateway of last resort is not set

1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
4.0.0.0/32 is subnetted, 1 subnets
B 4.4.4.4 [200/0] via 12.12.12.2, 00:04:00
144.144.0.0/32 is subnetted, 1 subnets
B 144.144.144.144 [200/0] via 12.12.12.2, 00:04:00
12.0.0.0/24 is subnetted, 1 subnets
C 12.12.12.0 is directly connected, Serial1/2
13.0.0.0/24 is subnetted, 1 subnets
C 13.13.13.0 is directly connected, Serial1/3
44.0.0.0/32 is subnetted, 1 subnets
B 44.44.44.44 [200/0] via 12.12.12.2, 00:04:00

It's clear that it prefers to take R2 to reach the networks in R4. Let's configure R3 so that all routes received by R3 will have a Local preference of 300


R3#config t
R3(config)#router bgp 123
R3(config-router)#bgp default local-preference 300

R1#sh ip bgp
BGP table version is 13, 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
Origin codes: i - IGP, e - EGP, ? - incomplete

Network Next Hop Metric LocPrf Weight Path
* i4.4.4.4/32 12.12.12.2 0 100 0 4 i
*>i 13.13.13.3 0 300 0 4 i
* i44.44.44.44/32 12.12.12.2 0 100 0 4 i
*>i 13.13.13.3 0 300 0 4 i
* i144.144.144.144/32
12.12.12.2 0 100 0 4 i
*>i 13.13.13.3 0 300 0 4 i

Immediately, even without clearing the BGP process, R3 now became the more preferred path to reach R4. Remember that in Local Preference, the higher the value, the more preferred.

Let's configure in R2 a route-map so the network 144.144.144.144/32 will have a local preference of 500. This will make R2 the best path to reach the mentioned network.


R2(config)#access-list 1 permit host 144.144.144.144
R2(config)#route-map LOCALPREF500 permit 10
R2(config-route-map)#match ip address 1
R2(config-route-map)#set local-preference 500
R2#(config)# router bgp 123
R2(config-router)#neighbor 24.24.24.4 route-map LOCALPREF500 in
R2# clear ip bgp *

R1#sh ip bgp
BGP table version is 14, 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
Origin codes: i - IGP, e - EGP, ? - incomplete

Network Next Hop Metric LocPrf Weight Path
*>i4.4.4.4/32 13.13.13.3 0 300 0 4 i
*>i44.44.44.44/32 13.13.13.3 0 300 0 4 i
*>i144.144.144.144/32
12.12.12.2 0 500 0 4 i
* i 13.13.13.3 0 300 0 4 i

Firstly, why is that the route-map has an "in" direction. It's because we are receiving the route from another router, R2 is not the one advertising. You can see now that path to 144.144.144.144/32 will have R2 as the next hop. If you noticed also, why is that for 4.4.4.4/32 and 44.44.44.44/32, there is no other path except through 13.13.13.3. Check the route-map above and you'll find the answer. There is no succedding line after line 10, which means, it will block out the subnets and not advertised it to R1.

Let's configure the 20th sequence of the route-map.


R2(config)#route-map LOCALPREF500 permit 20

Let's see now if there are changes.


R1#sh ip bgp
BGP table version is 16, 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
Origin codes: i - IGP, e - EGP, ? - incomplete

Network Next Hop Metric LocPrf Weight Path
* i4.4.4.4/32 12.12.12.2 0 100 0 4 i
*>i 13.13.13.3 0 300 0 4 i
* i44.44.44.44/32 12.12.12.2 0 100 0 4 i
*>i 13.13.13.3 0 300 0 4 i
*>i144.144.144.144/32
12.12.12.2 0 500 0 4 i
* i 13.13.13.3 0 300 0 4 i

That's it for local preference. Hopefully I can finish the BGP topics soon. :)

Comments

11 Responses to "BGP Local Preference"

Senthil said... October 3, 2009 at 1:08 AM

really good

Gurdeep Singh Rai said... January 4, 2011 at 5:12 PM

Nicely explained

Anonymous said... December 19, 2011 at 9:35 AM

thanks

Anonymous said... December 19, 2011 at 9:36 AM

thanks for the great explaination

Anonymous said... January 26, 2012 at 12:39 PM

Better than reading a book with a simple and detail configuration. Thanks

Sachin said... January 31, 2013 at 2:45 PM

really nice thanks...

Anonymous said... February 4, 2013 at 8:12 PM

Super Explaination!!! This is very helpful.... Its better than going for a class or reading a book... may be for more depth in variations we can opt books.... else your blog is good enuf!!! Kudo's to you!!!!

Anonymous said... March 27, 2013 at 2:40 PM

Amazing explanation, you saved me lots of reading on this subject.

Thanks a lot Pete

Anonymous said... June 6, 2013 at 10:19 PM

Amazing!... How about AS Path? Where should it be applied?

Sandeep Singh said... August 23, 2013 at 4:44 PM

Very nice explanation!

Deco said... March 18, 2014 at 2:26 AM

Very helpful. Thanks

Post a Comment

Certifications

Certifications

The Dreamer

A fun loving person who enjoys learning new things. Currently working as a Network Engineer supporting the global network of a Fortune 500 company. This blog serves as my notes for the labs I created for my CCIE journey. I can guarantee there are errors in my posts. If you spot them, please let me know.

Join my Facebook Page I WANT TO BE A CCIE

Donate to the Cause

My aim is to create materials for free and possibly a free lab. If you wish to help out, please send any amount. Thanks.

Join my Bandwagon

Blogs that I Read