PacketLab
BGP · Attributes and Path Selection

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.

Lab topologyIllustrative network
.1 / .2 · eBGP.5 / .6 · eBGP.9 / .10 · cost 10.13 / .14 · cost 10R1AS 65010R2AS 65020R3AS 65020R4AS 65020
Solid lines: physical links. Link labels use the last octet of 192.0.2.x; every link is a separate /30. AS labels identify the protocol relationship. Loopback0 is 10.255.0.N/32 for router RN. Exact interfaces and subnets are listed below.
LinkFirst endpointSecond endpoint
R1–R2R1 GigabitEthernet1: 192.0.2.1/30R2 GigabitEthernet1: 192.0.2.2/30
R1–R3R1 GigabitEthernet2: 192.0.2.5/30R3 GigabitEthernet1: 192.0.2.6/30
R2–R4R2 GigabitEthernet2: 192.0.2.9/30R4 GigabitEthernet1: 192.0.2.10/30
R3–R4R3 GigabitEthernet2: 192.0.2.13/30R4 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
end

R2

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
end

R3

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
end

R4

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
end
Outputs are illustrative, not recorded router results. Each lesson is a separate lab. Allow updates to converge after changes; the selected baseline path is an example when all earlier criteria tie.
R4# 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 i

With 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 200
R3# clear ip bgp 192.0.2.5 soft in
R4# 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 i
R4# 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.3

R4 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
exit
ip 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
exit
router bgp 65020
 address-family ipv4 unicast
  neighbor 192.0.2.5 route-map PREFER-R3 in
 exit-address-family
R3# clear ip bgp 192.0.2.5 soft in
R4# 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 i

The 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: 250

Restore 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-family
R3# clear ip bgp 192.0.2.5 soft in
R4# 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 i

Key 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.

Local Preference Quiz

Six questions · four options each · select one answer per question. Submit all answers to see your score and explanations.

1. What does LOCAL_PREF primarily influence?
2. Which value is preferred when earlier checks tie?
3. How does R4 learn the preference set by border R3?
4. Which can a higher LOCAL_PREF internal path beat?
5. What is the example default effective LOCAL_PREF?
6. Why might R4 see only R3’s path after the preference change?
Protocol and command references

Best-path comparison rules · BGP path attributes · Router-symbol attribution.