BGP attribute local preference is the second BGP attribute and it can be used to choose the exit path for an autonomous system. Here are the details:
- Local preference is the second BGP attribute.
- You can use local preference to choose the outbound external BGP path.
- Local preference is sent to all internal BGP routers in your autonomous system.
- Not exchanged between external BGP routers.
- Local preference is a well-known and discretionary BGP attribute.
- Default value is 100.
- The path with the highest local preference is preferred
Let me show you an example:

You can use local preference to configure your autonomous system to select a certain exit point. Instead of configuring weight on each router you can use local preference because it is exchanged on all internal BGP routers. By increasing the local preference to 800 we can make AS 1 send all traffic towards AS 2.
A well-known discretionary BGP attribute must be recognized by all BGP routers per RFC but its presence in a BGP update is optional.
Now let me show you how to configure local preference, here is the topology that we will use:

In the picture above we have two autonomous systems. R1 will advertise network 1.1.1.0/24 towards AS 2 and R4 will have to make a choice when it wants to reach this network. It can go through router R2 or R3, we’ll see how local preference influence this.
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 remote-as 2
R1(config-router)#neighbor 192.168.13.3 remote-as 2
R1(config-router)#network 1.1.1.0 mask 255.255.255.0
This is the configuration of R4, nothing spectacular here.
R2(config)#interface loopback 0
R2(config-if)#ip address 2.2.2.2 255.255.255.0
R2(config)#router ospf 1
R2(config-router)#network 192.168.24.0 0.0.0.255 area 0
R2(config-router)#network 2.2.2.0 0.0.0.255 area 0
R3(config)#interface loopback 0
R3(config-if)#ip address 3.3.3.3 255.255.255.0
R3(config)#router ospf 1
R3(config-router)#network 192.168.34.0 0.0.0.255 area 0
R3(config-router)#network 3.3.3.0 0.0.0.255 area 0
R4(config)#interface loopback 0
R4(config-if)#ip address 4.4.4.4 255.255.255.0
R4(config)#router ospf 1
R4(config-router)#network 192.168.24.0 0.0.0.255 area 0
R4(config-router)#network 192.168.34.0 0.0.0.255 area 0
R4(config-router)#network 4.4.4.0 0.0.0.255 area 0
I’ll configure OSPF within AS2 to prepare it for IBGP.
R3(config)#router bgp 2
R3(config-router)#neighbor 192.168.13.1 remote-as 1
R3(config-router)#neighbor 2.2.2.2 remote-as 2
R3(config-router)#neighbor 2.2.2.2 update-source loopback0
R3(config-router)#neighbor 4.4.4.4 remote-as 2
R3(config-router)#neighbor 4.4.4.4 update-source loopback0
R3(config-router)#neighbor 4.4.4.4 next-hop-self
R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 remote-as 1
R2(config-router)#neighbor 3.3.3.3 remote-as 2
R2(config-router)#neighbor 3.3.3.3 update-source loopback0
R2(config-router)#neighbor 4.4.4.4 remote-as 2
R2(config-router)#neighbor 4.4.4.4 update-source loopback0
R2(config-router)#neighbor 4.4.4.4 next-hop-self
R4(config)#router bgp 2
R4(config-router)#neighbor 2.2.2.2 remote-as 2
R4(config-router)#neighbor 2.2.2.2 update-source loopback 0
R4(config-router)#neighbor 3.3.3.3 remote-as 2
R4(config-router)#neighbor 3.3.3.3 update-source loopback 0
And above you can see the BGP configurations.
Now let’s find out what path R4 will use to reach network 1.1.1.0/24:
R4#show ip bgp
BGP table version is 2, local router ID is 4.4.4.4
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
* i1.1.1.0/24 3.3.3.3 0 100 0 1 i
*>i 2.2.2.2 0 100 0 1 i
All attributes are the same so it’s the router ID that makes the decision. All traffic is sent to R2 right now. Let’s play with the local preference…
R3(config)#router bgp 2
R3(config-router)#bgp default local-preference 600
The default local preference is 100 and you can change it if you like with the bgp default local-preference command.
R4#show ip bgp
BGP table version is 3, local router ID is 4.4.4.4
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
*>i1.1.1.0/24 3.3.3.3 0 600 0 1 i
* i 2.2.2.2 0 100 0 1 i
Now we see that R4 prefers to send traffic to network 1.1.1.0/24 towards R3 because the local preference is 600 > 100.
Of course we can accomplish the same thing with a route-map, here’s how:
R3(config)#router bgp 2
R3(config-router)#no bgp default local-preference 600
Let’s clean up first…
R3(config)#route-map LOCALPREF permit 10
R3(config-route-map)#set local-preference 700
R3(config)#router bgp 2
R3(config-router)#neighbor 192.168.13.1 route-map LOCALPREF in
Route-maps are a more flexible solution. If you don’t use a match statement in a route-map then everything is matched by default. You can use it to set the local preference to another value. Don’t forget to activate the route-map by binding it to a BGP neighbor.
R4#show ip bgp
BGP table version is 5, local router ID is 4.4.4.4
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
*>i1.1.1.0/24 3.3.3.3 0 700 0 1 i
* i 2.2.2.2 0 100 0 1 i
And as you can see above the local preference has changed.
hostname R4
!
interface Loopback 0
ip address 4.4.4.4 255.255.255.0
!
interface fastEthernet0/0
ip address 192.168.24.4 255.255.255.0
!
interface fastEthernet1/0
ip address 192.168.34.4 255.255.255.0
!
router ospf 1
network 192.168.24.0 0.0.0.255 area 0
network 192.168.34.0 0.0.0.255 area 0
network 4.4.4.0 0.0.0.255 area 0
!
router bgp 2
neighbor 2.2.2.2 remote-as 2
neighbor 2.2.2.2 update-source loopback 0
neighbor 3.3.3.3 remote-as 2
neighbor 3.3.3.3 update-source loopback 0
!
end
hostname R1
!
interface fastEthernet0/0
ip address 192.168.12.1 255.255.255.0
!
interface fastEthernet1/0
ip address 192.168.13.1 255.255.255.0
!
router bgp 1
neighbor 192.168.12.2 remote-as 2
neighbor 192.168.13.3 remote-as 2
network 1.1.1.0 mask 255.255.255.0
!
end
hostname R2
!
interface Loopback 0
ip address 2.2.2.2 255.255.255.0
!
interface fastEthernet0/0
ip address 192.168.12.2 255.255.255.0
!
interface fastEthernet2/0
ip address 192.168.24.2 255.255.255.0
!
router ospf 1
network 192.168.24.0 0.0.0.255 area 0
network 2.2.2.0 0.0.0.255 area 0
!
router bgp 2
neighbor 192.168.12.1 remote-as 1
neighbor 3.3.3.3 remote-as 2
neighbor 3.3.3.3 update-source loopback0
neighbor 4.4.4.4 remote-as 2
neighbor 4.4.4.4 update-source loopback0
neighbor 4.4.4.4 next-hop-self
!
end
hostname R3
!
interface Loopback 0
ip address 3.3.3.3 255.255.255.0
!
interface fastEthernet0/0
ip address 192.168.13.3 255.255.255.0
!
interface fastEthernet2/0
ip address 192.168.34.3 255.255.255.0
!
router ospf 1
network 192.168.34.0 0.0.0.255 area 0
network 3.3.3.0 0.0.0.255 area 0
!
router bgp 2
neighbor 192.168.13.1 remote-as 1
neighbor 2.2.2.2 remote-as 2
neighbor 2.2.2.2 update-source loopback0
neighbor 4.4.4.4 remote-as 2
neighbor 4.4.4.4 update-source loopback0
neighbor 4.4.4.4 next-hop-self
neighbor 192.168.13.1 route-map LOCALPREF in
!
route-map LOCALPREF permit 10
set local-preference 700
!
end
I hope you enjoyed reading this lesson, if you have any more questions feel free to ask!
No comments:
Post a Comment