BGP Local Preference
Set a preferred exit for your AS, and verify how that preference is carried to internal peers.
Network and baseline
R1 in AS 65010 advertises a /24 to two borders, R2 and R3, in AS 65020. R4 is an internal decision point. OSPF reaches the internal loopbacks; all three internal BGP pairs exist, and the borders use next-hop-self.
| Link | First endpoint | Second endpoint |
|---|---|---|
| R1–R2 | R1 GigabitEthernet1: 192.0.2.1/30 | R2 GigabitEthernet1: 192.0.2.2/30 |
| R1–R3 | R1 GigabitEthernet2: 192.0.2.5/30 | R3 GigabitEthernet1: 192.0.2.6/30 |
| R2–R4 | R2 GigabitEthernet2: 192.0.2.9/30 | R4 GigabitEthernet1: 192.0.2.10/30 |
| R3–R4 | R3 GigabitEthernet2: 192.0.2.13/30 | R4 GigabitEthernet2: 192.0.2.14/30 |
Complete baseline configurations
R1
hostname R1
ip cef
interface Loopback0
ip address 10.255.0.1 255.255.255.255
exit
interface Loopback10
ip address 198.51.100.1 255.255.255.0
exit
interface GigabitEthernet1
ip address 192.0.2.1 255.255.255.252
no shutdown
exit
interface GigabitEthernet2
ip address 192.0.2.5 255.255.255.252
no shutdown
exit
router bgp 65010
bgp router-id 10.255.0.1
no bgp default ipv4-unicast
neighbor 192.0.2.2 remote-as 65020
neighbor 192.0.2.6 remote-as 65020
address-family ipv4 unicast
no auto-summary
neighbor 192.0.2.2 activate
neighbor 192.0.2.6 activate
network 198.51.100.0 mask 255.255.255.0
exit-address-family
endR2
hostname R2
ip cef
interface Loopback0
ip address 10.255.0.2 255.255.255.255
exit
interface GigabitEthernet1
ip address 192.0.2.2 255.255.255.252
no shutdown
exit
interface GigabitEthernet2
ip ospf cost 10
ip address 192.0.2.9 255.255.255.252
no shutdown
exit
router ospf 1
router-id 10.255.0.2
network 10.255.0.2 0.0.0.0 area 0
passive-interface Loopback0
network 192.0.2.9 0.0.0.0 area 0
exit
router bgp 65020
bgp router-id 10.255.0.2
no bgp default ipv4-unicast
neighbor 192.0.2.1 remote-as 65010
neighbor 10.255.0.3 remote-as 65020
neighbor 10.255.0.3 update-source Loopback0
neighbor 10.255.0.4 remote-as 65020
neighbor 10.255.0.4 update-source Loopback0
address-family ipv4 unicast
no auto-summary
neighbor 192.0.2.1 activate
neighbor 10.255.0.3 activate
neighbor 10.255.0.3 next-hop-self
neighbor 10.255.0.4 activate
neighbor 10.255.0.4 next-hop-self
exit-address-family
endR3
hostname R3
ip cef
interface Loopback0
ip address 10.255.0.3 255.255.255.255
exit
interface GigabitEthernet1
ip address 192.0.2.6 255.255.255.252
no shutdown
exit
interface GigabitEthernet2
ip ospf cost 10
ip address 192.0.2.13 255.255.255.252
no shutdown
exit
router ospf 1
router-id 10.255.0.3
network 10.255.0.3 0.0.0.0 area 0
passive-interface Loopback0
network 192.0.2.13 0.0.0.0 area 0
exit
router bgp 65020
bgp router-id 10.255.0.3
no bgp default ipv4-unicast
neighbor 192.0.2.5 remote-as 65010
neighbor 10.255.0.2 remote-as 65020
neighbor 10.255.0.2 update-source Loopback0
neighbor 10.255.0.4 remote-as 65020
neighbor 10.255.0.4 update-source Loopback0
address-family ipv4 unicast
no auto-summary
neighbor 192.0.2.5 activate
neighbor 10.255.0.2 activate
neighbor 10.255.0.2 next-hop-self
neighbor 10.255.0.4 activate
neighbor 10.255.0.4 next-hop-self
exit-address-family
endR4
hostname R4
ip cef
interface Loopback0
ip address 10.255.0.4 255.255.255.255
exit
interface GigabitEthernet1
ip ospf cost 10
ip address 192.0.2.10 255.255.255.252
no shutdown
exit
interface GigabitEthernet2
ip ospf cost 10
ip address 192.0.2.14 255.255.255.252
no shutdown
exit
router ospf 1
router-id 10.255.0.4
network 10.255.0.4 0.0.0.0 area 0
passive-interface Loopback0
network 192.0.2.10 0.0.0.0 area 0
network 192.0.2.14 0.0.0.0 area 0
exit
router bgp 65020
bgp router-id 10.255.0.4
no bgp default ipv4-unicast
neighbor 10.255.0.2 remote-as 65020
neighbor 10.255.0.2 update-source Loopback0
neighbor 10.255.0.3 remote-as 65020
neighbor 10.255.0.3 update-source Loopback0
address-family ipv4 unicast
no auto-summary
neighbor 10.255.0.2 activate
neighbor 10.255.0.3 activate
exit-address-family
endR4# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
*>i 198.51.100.0/24 10.255.0.2 0 100 0 65010 i
*i 10.255.0.3 0 100 0 65010 iWith equal effective local preference and equal internal costs, the illustrated later tie-break chooses R2. LOCAL_PREF is well-known discretionary; higher wins and the example default is 100.
Set a default preference
On R3, raise the default preference for externally learned paths to 200, then refresh its external neighbor. Leave R2’s default at 100.
router bgp 65020
bgp default local-preference 200R3# clear ip bgp 192.0.2.5 soft inR4# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
*>i 198.51.100.0/24 10.255.0.3 0 200 0 65010 iR4# show ip route 198.51.100.0
Routing entry for 198.51.100.0/24
Known via "bgp 65020", distance 200, metric 0
* 10.255.0.3R4 receives the higher preference internally. R2 can also prefer the path via R3 over its own external path, because local preference is checked before external-versus-internal type. It then withdraws its old external candidate from R4 rather than relaying R3’s iBGP path back to another internal peer. Seeing one remaining candidate here is expected.
Choose a prefix with policy
On R3, remove the broad default change. Set preference 250 only for the target prefix received from R1, while permitting other paths without this setting.
router bgp 65020
bgp default local-preference 100
exitip prefix-list TARGET seq 5 permit 198.51.100.0/24
route-map PREFER-R3 permit 10
match ip address prefix-list TARGET
set local-preference 250
exit
route-map PREFER-R3 permit 20
exitrouter bgp 65020
address-family ipv4 unicast
neighbor 192.0.2.5 route-map PREFER-R3 in
exit-address-familyR3# clear ip bgp 192.0.2.5 soft inR4# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
*>i 198.51.100.0/24 10.255.0.3 0 250 0 65010 iThe policy is applied inbound at the AS entry point, before R3 advertises the chosen route internally. Applying this outbound toward the external AS would not tell your own internal routers which exit to use.
Understand the scope
LOCAL_PREF controls outbound traffic from the choosing AS; it is not normally sent to ordinary eBGP neighbors. Weight remains local to one router. Higher local preference cannot rescue an unreachable next hop, and an earlier nonzero weight difference can still determine the winner.
Illustrative internal UPDATE fields
R3 → R4, iBGP UPDATE
NLRI: 198.51.100.0/24
AS_PATH: 65010
NEXT_HOP: 10.255.0.3
LOCAL_PREF: 250Restore the baseline
Remove the per-prefix policy on R3 and refresh the external peer. Both borders then use default 100 again.
router bgp 65020
address-family ipv4 unicast
no neighbor 192.0.2.5 route-map PREFER-R3 in
exit-address-familyR3# clear ip bgp 192.0.2.5 soft inR4# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
*>i 198.51.100.0/24 10.255.0.2 0 100 0 65010 i
*i 10.255.0.3 0 100 0 65010 iKey Takeaways
- Higher effective LOCAL_PREF is preferred when weight ties.
- LOCAL_PREF is carried to internal peers and normally not to ordinary external peers.
- Set exit policy at the AS entry point using a default or an inbound route map.
- An internal candidate with higher preference can beat a direct external candidate.
- A policy change can withdraw an alternative, so the remote path count need not stay constant.
Protocol and command references
Best-path comparison rules · BGP path attributes · Router-symbol attribution.