#

Thursday, August 17, 2017

BGP Path Selection by Local Preference

Local Preference is the 2nd BGP attribute in the list.. Because Weight is a Cisco proprietary, Local Preference becomes the most well known attribute in the industry..

(1) Can use to choose the best path for outbound traffic..
(2) Local Preference is sent to all iBGP peers only..
(3) Path with the highest Local Preference is preferred, default is 100..

Let's see an example..

Basic routing (EIGRP) configurations in AS-1

R1(config)#router eigrp 10
R1(config-router)#network 192.168.12.0
R1(config-router)#network 192.168.13.0
R1(config-router)#network 1.0.0.0

R2(config)#router eigrp 10
R2(config-router)#network 192.168.12.0
R2(config-router)#network 2.0.0.0

R3(config)#router eigrp 10
R3(config-router)#network 192.168.13.0
R3(config-router)#network 3.0.0.0

Basic routing (static) on R1 to reach the R2-R4 & R3-R4 links

R1(config)#ip route 192.168.24.0 255.255.255.0 192.168.12.2
R1(config)#ip route 192.168.34.0 255.255.255.0 192.168.13.3

Basic BGP configurations

R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 remote-as 1
R1(config-router)#neighbor 2.2.2.2 update-source Loopback0
R1(config-router)#neighbor 3.3.3.3 remote-as 1
R1(config-router)#neighbor 3.3.3.3 update-source Loopback0

R2(config)#router bgp 1
R2(config-router)#neighbor 1.1.1.1 remote-as 1  
R2(config-router)#neighbor 1.1.1.1 update-source lo0
R2(config-router)#neighbor 3.3.3.3 remote-as 1          
R2(config-router)#neighbor 3.3.3.3 update-source lo0
R2(config-router)#neighbor 192.168.24.4 remote-as 2

R3(config)#router bgp 1
R3(config-router)#neighbor 1.1.1.1 remote-as 1
R3(config-router)#neighbor 1.1.1.1 update-source lo0
R3(config-router)#neighbor 2.2.2.2 remote-as 1      
R3(config-router)#neighbor 2.2.2.2 update-source lo0
R3(config-router)#neighbor 192.168.34.4 remote-as 2

R4(config)#router bgp 2
R4(config-router)#neighbor 192.168.24.2 remote-as 1
R4(config-router)#neighbor 192.168.34.3 remote-as 1
R4(config-router)#network 4.4.4.0 mask 255.255.255.0
R4(config-router)#network 5.5.5.0 mask 255.255.255.0







Now by default you can see that the path through R2 is preferred to reach R4's networks..

Give preference to all the routes coming from one router?

If you want to give higher preference to all routes from R3;

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








Now you can see the best path is changed with the Local Preference..

We only add a configuration line to R3, let's see the R2's BGP table..






You can see that the Local Preference is 300, but the routes are not given the preference. This is because the next hop is directly connected.. Unless otherwise, the routes advertised from R3 will be given preference by all the iBGP neighbors in AS-1..

Let's look at the R3's BGP table..









Well here is some thing to remember.. Local Preference is not been added to the configured router's BGP table. The router will only advertise it to it's iBGP neighbors..

Give preference to some routes coming from one router?

Now If you want to give preference only to some routes learned from one router you have to use a route-map.
Let's say that R4's 4.4.4.0/24 route to be preferred through R2 on iBGP peers in AS-1..
Here is how to do it..

R2(config)#access-list 10 permit 4.4.4.0 0.0.0.255

R2(config)#route-map SET_LP permit 10
R2(config-route-map)#match ip address 10
R2(config-route-map)#set local-preference 400
R2(config-route-map)#route-map SET_LP permit 20

R2(config-route-map)#router bgp 1
R2(config-router)#neighbor 192.168.24.4 route-map SET_LP in









Now you can see the preference 400 is advertised with the 4.4.4.0/24 route to the iBGP neighbors of R2. Let's see R2's BGP table now..












Well you can see the 4.4.4.0/24 route is given the 400 preference even in the R2's (the router which the route-map is configured) BGP table.. But you saw if the preference is given under BGP commands, it is not added to it's BGP table.. This is because the policy is applied inbound to the traffic and the other case really applied to the outbound to neighbors..

Give preference to some routes advertised to some neighbors?

This can be achieved through route maps too. We applied the route map on R2 to an eBGP neighbor in bound. How about applying it to an iBGP neighbor outbound..

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









Here you can see the preference value is not added to R3's & R2's BGP tables. Because the route map is applied outbound, R2 does not update the preference values itself..

To know something interestin please go here.

No comments:

Post a Comment