What is the Local Preference?
Local Preference (aka LOCAL_PREF) is a BGP well-known attribute that is used when there are multiple exit paths out from a single AS exist. Whereas the MED is used to tell routers outside of an AS which entrance path to take, the LOCAL_PREF is used locally within an AS to tell routers which exit path to take out from an AS.
In addition,
- The highest local preference is selected.
- The local preference is only advertised between iBGP peers; the LOCAL_PREF attribute is never advertised outside of an AS.
Figure 1 - BGP LOCAL_PREF.
Example
Let us look at an example of LOCAL_PREF in action.
Topology
Our topology and example are based upon:
- 2 networks being advertised from R1 - 10.1.200.0/24 and 10.2.200.0/24.
- R4 BGP table will select R2 as the best path to both networks.
- A route map configured on R3 to add a LOCAL_PREF attribute when advertising routes to R4.
Figure 2 - LOCAL_PREF Topology example.
First of all, if we look at the best path, we can see that the best path selected (denoted via >) for both prefixes (10.[1-2].200.0/24) is 2.2.2.2 (R2).
R4#show ip bgp
BGP table version is 4, local router ID is 10.1.100.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,
t secondary path,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
* i 10.1.200.0/24 3.3.3.3 0 100 0 100 i
*>i 2.2.2.2 0 100 0 100 i
* i 10.2.200.0/24 3.3.3.3 0 100 0 100 i
*>i 2.2.2.2 0 100 0 100 i
Configuration
Our configuration will follow the following steps on R3:
- An access list will define the network.
- A route map will be assigned the network (ACL) to an action.
- The route map action will be to set the LOCAL_PREF value for the route.
- The route map will then be assigned to R3 against the R4 neighbor, for outbound advertisements.
Let's begin…
R3
R3(config)#access-list 2 permit 10.2.200.0 0.0.0.255
R3(config)#route-map LOCAL_PREF_200 permit 10
R3(config-route-map)#match ip add 2
R3(config-route-map)#set local-preference 200
R3(config-route-map)#route-map LOCAL_PREF_200 permit 20
R3(config-route-map)#set local-preference 100
R3(config-route-map)#exit
R3(config)#router bgp 200
R3(config-router)#neighbor 4.4.4.4 route-map LOCAL_PREF_200 out
R3(config)#do clear ip bgp * soft out
Verification
We can now verify that our previous route map has had the desired result.
As we can see from the BGP table for 10.2.200.0 that 3.3.3.3 has now been marked as the best route due to the LOCAL_PREF value being 200. However, for the prefix 10.1.200.0/24 this still goes via 2.2.2.2, with both R2 and R3
R4#show ip bgp
BGP table version is 5, local router ID is 10.1.100.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,
t secondary path,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
Network Next Hop Metric LocPrf Weight Path
* i 10.1.200.0/24 3.3.3.3 0 100 0 100 i
*>i 2.2.2.2 0 100 0 100 i
*>i 10.2.200.0/24 3.3.3.3 0 200 0 100 i
* i 2.2.2.2 0 100 0 100 i
R4#show ip bgp 10.2.200.0
BGP routing table entry for 10.2.200.0/24, version 5
Paths: (2 available, best #1, table default)
Not advertised to any peer
Refresh Epoch 1
100
3.3.3.3 from 3.3.3.3 (3.3.3.3)
Origin IGP, metric 0, localpref 200, valid, internal, best
rx pathid: 0, tx pathid: 0x0
Refresh Epoch 1
100
2.2.2.2 from 2.2.2.2 (2.2.2.2)
Origin IGP, metric 0, localpref 100, valid, internal
rx pathid: 0, tx pathid: 0