BGP Local Preference: Primary/Backup and Transit Tiers
Two transit providers, one bill you would rather not pay, and traffic that keeps leaving through the wrong one: that is the day most engineers meet BGP local preference. LOCAL_PREF is the knob that decides where traffic leaves your autonomous system. It is set by you, on your own border routers, and it is shared by every router in the AS, so they all agree on the exit. It beats AS_PATH length, ORIGIN and MED, which is why it carries most of the routing policy of the Internet: customer routes before peer routes before transit routes. This part of the series covers the attribute itself (bytes, defaults, error handling), then the three designs operators actually build with it, tested in a GoBGP lab and compared with what large transit networks publish today.
- What it is: LOCAL_PREF is type code 5, a well-known discretionary attribute holding a 32-bit unsigned number. Higher is better. Default 100 on Cisco, Junos and FRR.[1][8][10]
- Scope: it MUST be sent to iBGP peers and MUST NOT be sent to eBGP peers (except confederations); a value received over eBGP is ignored.[1][2]
- Position: it is the first shared step of best-path selection (Cisco checks its local WEIGHT before it), before AS_PATH length, ORIGIN and MED.[8][13]
- Three designs: primary/backup exit (lower the backup), business tiers (customer > peer > transit, plus tagging so you do not give free transit), and community-driven values that let customers move their own traffic.[4][13]
- Lab: with defaults our border router sent traffic for a customer's prefix through a peer; with a tiered policy the customer won despite a path twice as long, a backup transit was hidden until the primary failed, and the switch-over reached the observers 18 ms after the session went down.[15]
- Real networks: Arelion gives customers 200 and peers 150, Cogent gives customers 130, Lumen 100 for customers and 86 for peers, all with customer communities to lower the value.[14]
What BGP local preference is
RFC 4271 defines LOCAL_PREF in one sentence: it is "a well-known attribute that is a four-octet unsigned integer. A BGP speaker uses it to inform its other internal peers of the advertising speaker's degree of preference for an advertised route".[1] Three parts of that definition matter in practice.
Well-known discretionary. Every BGP implementation must understand it, but not every UPDATE has to carry it. Section 5.1.5 then tightens the rule by peer type: LOCAL_PREF "SHALL be included in all UPDATE messages that a given BGP speaker sends to other internal peers", and a speaker "MUST NOT include this attribute in UPDATE messages it sends to external peers, except in the case of BGP Confederations". If an external peer sends it anyway, "this attribute MUST be ignored by the receiving speaker".[1] So in a correct network the attribute is mandatory on iBGP and absent on eBGP. It is local to one AS, which is where the name comes from.
Degree of preference. The RFC builds the decision process around a "degree of preference" that Phase 1 calculates for every route. For a route learned from an internal peer, "either the value of the LOCAL_PREF attribute is taken as the degree of preference, or the local system computes the degree of preference of the route based on preconfigured policy information. Note that the latter may result in formation of persistent routing loops." For a route learned from an external peer the speaker computes it from policy, and the result "MUST be used as the LOCAL_PREF value in any IBGP readvertisement".[1] In plain words: the border router decides, the iBGP routers obey. If internal routers start overriding the value they received, two routers can each point at the other as the better exit.
Higher wins. "The higher degree of preference MUST be preferred."[1] This is the opposite of MED and of IGP metrics, where lower wins. The value range is 0 to 4,294,967,295 on IOS XR and Junos.[9][10]
Why it is only inside the AS
The reason is economic, not technical. Your preference among exits reflects your contracts: which neighbour pays you, which one you pay, and which one you exchange traffic with for free. A neighbour has no business knowing those numbers and no reason to obey them. Caesar and Rexford describe LocalPref as "an integer value set at and propagated throughout the local AS and filtered before sending to neighboring ISPs", and list it as the one step of the decision process that is controlled purely locally.[13] If you want a neighbour to change its LOCAL_PREF for your routes, you cannot send the attribute; you send a community it has agreed to translate (the third design below).
LOCAL_PREF on the wire
The attribute is always seven bytes: flags 0x40 (well-known, transitive), type 0x05, length 0x04, and the value. This is the UPDATE our raw iBGP peer I received from router r1 for a customer prefix in phase B of the lab, after r1's import policy had set LOCAL_PREF 200 (GoBGP 4.11 lab output, bytes after the 19-byte header):[15]
00 00 00 2e 40 01 01 00 40 02 12 02 04 00 00 fd f2 00 00 fd f2 00 00 fd f2 00 00 fb f4 40 03 04 7f 00 02 5f 40 05 04 00 00 00 c8 c0 08 04 fd e9 00 64 18 c0 00 02
withdrawn len 0 | path attributes 0x2e = 46 bytes
40 01 01 00 ORIGIN IGP
40 02 12 02 04 0000fdf2 0000fdf2 AS_PATH: SEQUENCE of 4:
0000fdf2 0000fbf4 65010 65010 65010 64500
40 03 04 7f 00 02 5f NEXT_HOP 127.0.2.95 (customer C, unchanged on iBGP)
40 05 04 00 00 00 c8 LOCAL_PREF 200 <- set by r1's import policy
c0 08 04 fd e9 00 64 COMMUNITIES 65001:100 (our 'from customer' tag)
18 c0 00 02 NLRI 192.0.2.0/24
The same route as r1 sent it to eBGP neighbour X a millisecond later has no 40 05 at all: AS 65001 is prepended to the AS_PATH, NEXT_HOP becomes r1 (127.0.2.91), and the LOCAL_PREF of 200 stays inside our AS (40 01 01 00 40 02 16 02 05 00 00 fd e9 00 00 fd f2 00 00 fd ...).[15]
What a receiver does with odd values
RFC 7606 replaced the old "reset the session" reaction for most UPDATE errors. For LOCAL_PREF it says: if the attribute "is received from an external neighbor, it SHALL be discarded using the approach of 'attribute discard'"; if received from an internal neighbor, "it SHALL be considered malformed if its length is not equal to 4", and the UPDATE is handled as treat-as-withdraw.[2] We sent five test routes from iBGP peer I and the same prefixes from eBGP peer T (AS 65040, one-ASN path) in phase A, with no policy configured:[15]
- LOCAL_PREF 0 from iBGP: accepted, and it lost to T's eBGP route even though T's AS_PATH was longer (one ASN against none). An eBGP route without LOCAL_PREF counts as 100, and 100 > 0.
- LOCAL_PREF 4,294,967,295: accepted and best. The full 32-bit range works.
- No LOCAL_PREF on iBGP: accepted and treated as 100. The two routes tied on LOCAL_PREF, and I's route won on the next step, the shorter AS_PATH. Cisco documents exactly this ("A path without LOCAL_PREF is considered to have had the value set with the bgp default local-preference command, or to have a value of 100 by default"), and Junos handles such a route "as if it were received with a LOCAL_PREF value of 100".[8][10]
- Length 3 and flags 0xC0 (optional bit set): treat-as-withdraw, with these log lines and the Discarded counter of the session at 2. The session stayed up.
- LOCAL_PREF 999 from eBGP peer T: ignored. T's route was stored without it and r1 advertised it to iBGP with 100.
$ grep LOCAL_PREF r1.log; gobgp neighbor 127.0.2.97 | grep Discarded # GoBGP 4.11 lab output
level=WARN msg="the received Update message was treated as withdraw" Key=127.0.2.97 Error="local pref length isn't correct"
level=WARN msg="the received Update message was treated as withdraw" Key=127.0.2.97 Error="flags are invalid. attribute type: BGP_ATTR_TYPE_LOCAL_PREF, expect: TRANSITIVE, actual: TRANSITIVE|OPTIONAL"
Discarded: 0 2
$ gobgp global rib -a ipv4 10.10.3.0/24 # iBGP route without LOCAL_PREF vs eBGP route
Network Next Hop AS_PATH Age Attrs
*> 10.10.3.0/24 127.0.2.97 00:00:03 [{Origin: i}]
* 10.10.3.0/24 127.0.2.99 65040 00:00:03 [{Origin: i}]
One detail of GoBGP's display is worth knowing when you read lab output: in phase A, routes learned from eBGP neighbours showed no LocalPref in r1's table at all, but r2 received them with 100. GoBGP adds the default when it advertises a route to iBGP. Junos documents the same model: "The default LOCAL_PREF path attribute value of 100 applies at export time only, when the routes are exported from the routing table into BGP."[10] Cisco's detailed show ip bgp output prints "localpref 100" on eBGP paths too (see the RouteViews output in part 8). The decision result is the same.
Where it sits in best-path selection
Cisco's best-path document puts LOCAL_PREF second: "1. Prefer the path with the highest WEIGHT ... WEIGHT is a Cisco-specific parameter. It is local to the router on which it is configured. 2. Prefer the path with the highest LOCAL_PREF."[8] FRR uses the same order with weight first.[11] RFC 4271 has no weight; its Phase 1 degree of preference is LOCAL_PREF, and only when two routes have the same degree does Phase 2 go on to AS_PATH length, ORIGIN, MED, eBGP over iBGP, IGP cost and the tie-breakers.[1]
The order is the reason LOCAL_PREF is the policy knob. Caesar and Rexford put it plainly: "By changing LocalPref, an operator can force a route with a longer AS path to be chosen over a shorter one", and MED "was placed lower in the decision process as this allows an ISP to override these suggestions".[13] Everything below LOCAL_PREF is either chosen by your neighbours (AS_PATH length, ORIGIN, MED) or fixed by the protocol. If you want a decision that your neighbours cannot undo by prepending, you make it with LOCAL_PREF.
Two side effects follow from that power. First, LOCAL_PREF also hides routes: a border router whose best path is now an iBGP route learned from another border does not advertise its own eBGP route to iBGP peers any more (iBGP split horizon), so the backup path exists only on that one router. Second, the WEIGHT step above it is the classic trap: a weight set on one Cisco router overrides the LOCAL_PREF that the rest of the AS agreed on, and only that router behaves differently.[8]
The lab: one AS, five kinds of neighbours
We built the topology of Figure 4 with real GoBGP 4.11 daemons on loopback addresses. AS 65001 has two border routers: r1 (127.0.2.91) and r2 (127.0.2.92), connected by iBGP. Transit A, r3 (AS 65003), connects to r1; transit B, r4 (AS 65004), connects to r2. Both transits originate 203.0.113.0/24. Five more neighbours of r1 are our own Python BGP speakers that log every byte: customers C (AS 65010) and X (AS 65030), settlement-free peer P (AS 65020), a third transit T (AS 65040), and an iBGP observer I. Phase A ran with no policy at all. Phase B added the policy described below. Every output in this article is real lab output from GoBGP; the Cisco, Junos and FRR blocks further down are configuration examples from vendor documentation.[12][15]
Design 1: primary and backup exit
The most common request: "use transit A, and use transit B only if A fails". Without policy BGP does not do that. In phase A each border router preferred its own eBGP route (step 7, eBGP over iBGP), so traffic left through both providers, each border sending its own traffic out of its own transit (GoBGP 4.11 lab output):[15]
$ gobgp -p 50071 global rib -a ipv4 203.0.113.0/24 # r1, phase A
Network Next Hop AS_PATH Age Attrs
*> 203.0.113.0/24 127.0.2.93 65003 00:00:03 [{Origin: i}]
* 203.0.113.0/24 127.0.2.94 65004 00:00:03 [{Origin: i} {LocalPref: 100}]
$ gobgp -p 50072 global rib -a ipv4 203.0.113.0/24 # r2, phase A
Network Next Hop AS_PATH Age Attrs
*> 203.0.113.0/24 127.0.2.94 65004 00:00:03 [{Origin: i}]
* 203.0.113.0/24 127.0.2.93 65003 00:00:03 [{Origin: i} {LocalPref: 100}]
The fix is a single import policy on r2: routes from r4 get LOCAL_PREF 50. Lowering the backup is safer than raising the primary, because a new session that nobody configured yet also gets 100 and so can never win against the primary by accident. With the policy, r2 has two paths: its own eBGP path at 50 and r1's path at 100 via iBGP. LOCAL_PREF is compared before eBGP/iBGP, so r2 sends its traffic across the AS to r1 (phase B):
$ gobgp -p 50072 global rib -a ipv4 203.0.113.0/24 # r2, phase B
Network Next Hop AS_PATH Age Attrs
*> 203.0.113.0/24 127.0.2.93 65003 00:00:03 [{Origin: i} {LocalPref: 100} {Communities: 65001:300}]
* 203.0.113.0/24 127.0.2.94 65004 00:00:03 [{Origin: i} {LocalPref: 50} {Communities: 65001:300}]
$ gobgp -p 50071 global rib -a ipv4 203.0.113.0/24 # r1, phase B: the backup is invisible here
Network Next Hop AS_PATH Age Attrs
*> 203.0.113.0/24 127.0.2.93 65003 00:00:03 [{Origin: i} {LocalPref: 100} {Communities: 65001:300}]
Note the second table. r1 does not even know that transit B exists, because r2 no longer advertises a route that is not its best. That is good for the table size and bad for convergence: when the primary fails, r2 must first notice, then select its own route, then advertise it to r1.
Failover and return, measured
We disabled the r1-r3 session from r3 and polled the best path on both routers every 50 ms, while raw peers I and X time-stamped the UPDATEs that r1 sent. The withdrawal of the r3 path and the replacement path via r4 reached our observer X 18 ms after the disable command was issued; at the first poll both routers already used r4. When we enabled the session again, the route via r3 was back 1.2 s later, the time it took to re-establish the r1-r3 session, and both routers returned to the primary without any command. With LOCAL_PREF the backup is pre-emptive by design.[15]
$ gobgp -p 50072 global rib -a ipv4 203.0.113.0/24 # r2 while r3 is down
Network Next Hop AS_PATH Age Attrs
*> 203.0.113.0/24 127.0.2.94 65004 00:00:07 [{Origin: i} {LocalPref: 50} {Communities: 65001:300}]
$ gobgp -p 50071 global rib -a ipv4 203.0.113.0/24 # r1 while r3 is down: via r2, LOCAL_PREF 50
Network Next Hop AS_PATH Age Attrs
*> 203.0.113.0/24 127.0.2.94 65004 00:00:00 [{Origin: i} {LocalPref: 50} {Communities: 65001:300}]
A loopback lab has no link delay and no detection delay: the session went down because we told it to. In a real network the switch-over time is dominated by failure detection (hold timer, BFD, or interface down events) and by how fast the remaining router can advertise its newly best path. The lab shows the logic and the order of events, not production timings.
Design 2: customer > peer > transit
The second design reflects money. Traffic sent to a customer earns revenue, traffic to a settlement-free peer costs nothing per bit, traffic to a transit provider costs money. Caesar and Rexford describe how ISPs encode this: "assigning a non-overlapping range of LocalPref values to each type of peering relationship; for example LocalPref values in the range 90-99 might be used for customers, 80-89 for peers, 70-79 for providers, and 60-69 for backup links".[13] Non-overlapping ranges matter: you can then do traffic engineering inside a class (move some traffic from one transit to another) without ever pushing a peer route above a customer route.
Our phase-B policy on r1 used 200 for customers, 150 for the peer and 100 for transits. The test prefix 192.0.2.0/24 belongs to AS 64500, which is multihomed: it reaches us through customer C, who prepends heavily because the link is its backup (four ASNs), and through peer P and transit T (two ASNs each). In phase A the shortest path won, and the tie between P and T was broken by the lowest router ID, so we sent traffic for our own customer's customer through a peer:[15]
$ gobgp -p 50071 global rib -a ipv4 192.0.2.0/24 # r1, phase A (no policy)
Network Next Hop AS_PATH Age Attrs
*> 192.0.2.0/24 127.0.2.96 65020 64500 00:00:03 [{Origin: i}]
* 192.0.2.0/24 127.0.2.99 65040 64500 00:00:03 [{Origin: i}]
* 192.0.2.0/24 127.0.2.95 65010 65010 65010 64500 00:00:03 [{Origin: i}]
$ gobgp -p 50071 global rib -a ipv4 192.0.2.0/24 # r1, phase B (customer 200, peer 150, transit 100)
Network Next Hop AS_PATH Age Attrs
*> 192.0.2.0/24 127.0.2.95 65010 65010 65010 64500 00:00:03 [{Origin: i} {LocalPref: 200} {Communities: 65001:100}]
* 192.0.2.0/24 127.0.2.96 65020 64500 00:00:03 [{Origin: i} {LocalPref: 150} {Communities: 65001:200}]
* 192.0.2.0/24 127.0.2.99 65040 64500 00:00:03 [{Origin: i} {LocalPref: 100} {Communities: 65001:300}]
Phase B is the textbook result: the customer path wins with four ASNs against two. Whether you want that for a prepended backup link is a business question. The customer prepended to say "use my other link". If you still prefer its route because it pays you, the customer's inbound traffic engineering stops working at your AS. Many transit networks therefore let customers lower the value themselves (Design 3), which respects the customer's intent without giving up the tier model.
The other half: tag on import, filter on export
LOCAL_PREF alone only decides which route you use. The business model also decides which routes you advertise: routes from peers and transits must not be sent to other peers and transits, or you carry their traffic for free. RFC 9234 writes the Gao-Rexford rules into the protocol: a customer, and likewise a peer, "MAY propagate any route learned from a Customer, or that is locally originated", and "All other routes MUST NOT be propagated".[6] The classic implementation is the one Caesar and Rexford describe: tag each route with a community that records where it came from when it enters the AS, and match that community when it leaves.[13]
Our import policy added 65001:100 to customer routes, 65001:200 to peer routes and 65001:300 to transit routes; the export policy towards P, T and r3 allowed only 65001:100 and our own 65001:1. The difference is visible in what peer P received (GoBGP 4.11 lab output):[15]
$ gobgp -p 50071 neighbor 127.0.2.96 adj-out -a ipv4 # to peer P, phase A (no policy): a route leak
ID Network Next Hop AS_PATH AttrsFiltered
2 10.10.1.0/24 127.0.2.91 65001 65040 [{Origin: i}]not filtered
1 10.10.2.0/24 127.0.2.91 65001 [{Origin: i}]not filtered
2 10.10.3.0/24 127.0.2.91 65001 [{Origin: i}]not filtered
1 10.10.4.0/24 127.0.2.91 65001 65040 [{Origin: i}]not filtered
1 10.10.5.0/24 127.0.2.91 65001 65040 [{Origin: i}]not filtered
1 100.64.20.0/24 127.0.2.91 65001 65040 [{Origin: i}]not filtered
1 198.18.0.0/24 127.0.2.91 65001 [{Origin: i} {Communities: 65001:1}]not filtered
1 198.51.100.0/24 127.0.2.91 65001 65010 [{Origin: i} {Communities: 65001:80}]not filtered
1 203.0.113.0/24 127.0.2.91 65001 65003 [{Origin: i}]not filtered
$ gobgp -p 50071 neighbor 127.0.2.96 adj-out -a ipv4 # to peer P, phase B (customer + own routes only)
ID Network Next Hop AS_PATH AttrsFiltered
3 192.0.2.0/24 127.0.2.91 65001 65010 65010 65010 64500 [{Origin: i} {Communities: 65001:100}]not filtered
1 198.18.0.0/24 127.0.2.91 65001 [{Origin: i} {Communities: 65001:1}]not filtered
In phase A peer P received the transit route 203.0.113.0/24 and transit T's 100.64.20.0/24: P could have sent traffic for those destinations into our network and out through a provider we pay, which is exactly the kind of route leak RFC 9234 was written to stop. In phase B P saw only our own prefix and our customer's 192.0.2.0/24.
One consequence surprised us at first. 198.51.100.0/24 from customer C did not appear in P's list in phase B, although it is a customer route. Its best path at r1 was the transit path (next section), and BGP advertises only the best path, whose tag is 65001:300. Only when the customer removed its backup community did the route return to P's list. Export filters work on the best path, so a customer's backup request also changes what your peers see.
Design 3: community-driven LOCAL_PREF
Since a customer cannot send LOCAL_PREF across eBGP, it needs another way to say "treat this link as backup". RFC 1998 (1996) described the answer that is still used today: the provider publishes community values, and its import policy translates them into LOCAL_PREF. MCI's table in that RFC used 100 for customer routes, 90 for customer backup routes, 80 for routes from other ISPs and 70 for customer-provided backup, with communities 3561:70, 3561:80 and 3561:90 for the customer to choose from.[4] RFC 8195 shows the same idea with large communities: functions for "normal customer route", "backup customer route", "peering route", "upstream transit route" and "fallback route", e.g. 64497:9:0 to "Assign LOCAL_PREF for a customer backup route".[5]
Our phase-B policy matched 65001:80 from customers and set LOCAL_PREF 80, below the transit value of 100. Customer C announced 198.51.100.0/24 with that community; transit T also had a path to it (65040 65010):[15]
$ gobgp -p 50071 global rib -a ipv4 198.51.100.0/24 # phase B, C sends 65001:80
Network Next Hop AS_PATH Age Attrs
*> 198.51.100.0/24 127.0.2.99 65040 65010 00:00:03 [{Origin: i} {LocalPref: 100} {Communities: 65001:300}]
* 198.51.100.0/24 127.0.2.95 65010 00:00:03 [{Origin: i} {LocalPref: 80} {Communities: 65001:80, 65001:100}]
$ gobgp -p 50071 global rib -a ipv4 198.51.100.0/24 # C re-announces without the community
Network Next Hop AS_PATH Age Attrs
*> 198.51.100.0/24 127.0.2.95 65010 00:00:02 [{Origin: i} {LocalPref: 200} {Communities: 65001:100}]
* 198.51.100.0/24 127.0.2.99 65040 65010 00:01:01 [{Origin: i} {LocalPref: 100} {Communities: 65001:300}]
The customer moved our outbound traffic for its own prefix without opening a ticket, and moved it back with one re-announcement: our check two seconds after it showed the customer path at 200 again. Two details in the outputs are worth copying into a real policy. The statement that matches the backup community comes before the general customer statement; otherwise the first match sets 200 and the community is never looked at. And the route kept its customer tag 65001:100 even at LOCAL_PREF 80, so the export filter still treats it as a customer route when it is best.
What real transit networks publish
Many large networks document their LOCAL_PREF classes and customer communities in the remarks of their aut-num objects in the IRR. We queried four of them on 1 December 2026:[14]
- Arelion (AS1299), RIPE database: "Community Action (default local pref 200)";
1299:50"Set local pref 50 within AS1299 (lowest possible)";1299:150"Set local pref 150 within AS1299 (equal to peer, backup)", plus regional variants. - Cogent (AS174), RADB: "All customer routes announced to Cogent will receive a default local preference of 130", with communities from
174:10"least prefered" over174:70"below peers" to174:140"above customer default". - Lumen (AS3356), LEVEL3 IRR: "Localpref will be set to 100 by default", "Localpref for non-customer peers is generally set to 86", and customer communities
3356:70,3356:80,3356:90and others. The same object states that communities from non-customers "will have all of their communities stripped from them at ingress". - Orange (AS5511), RIPE database: "Default LOCAL_PREF= 100" and
5511:70,5511:80,5511:90.
The numbers differ completely (a customer route is 200 at Arelion and 100 at Lumen), but the order is the same everywhere: customer above peer, and a customer can push its own route down to or below peer level. The phrase "equal to peer, backup" in Arelion's object is the design in a nutshell: if a customer sets 1299:150, Arelion's routers see a tie with peer routes and fall through to AS_PATH length. Note also Lumen's warning: these communities work only on customer sessions. A community that sets LOCAL_PREF must never be honoured from a peer or a transit, or any network on the Internet could steer your traffic.
Configuration examples
These are configuration examples written from vendor documentation, not output from our lab. The GoBGP part is the policy we ran in phase B.[8][9][10][11][12]
! Cisco IOS XE: tiers + customer backup community on a border router
ip community-list standard CUST-BACKUP permit 65001:80
route-map FROM-CUSTOMER permit 10
match community CUST-BACKUP
set local-preference 80
set community 65001:100 additive
route-map FROM-CUSTOMER permit 20
set local-preference 200
set community 65001:100 additive
route-map FROM-PEER permit 10
set local-preference 150
set community 65001:200 additive
!
router bgp 65001
neighbor 192.0.2.1 route-map FROM-CUSTOMER in
neighbor 198.51.100.1 route-map FROM-PEER in
! check: show ip bgp 192.0.2.0 (LocPrf column / "localpref 200")
! Cisco IOS XR: backup transit
route-policy FROM-TRANSIT-B
set local-preference 50
set community (65001:300) additive
end-policy
router bgp 65001
neighbor 203.0.113.1
address-family ipv4 unicast
route-policy FROM-TRANSIT-B in
# Junos: same backup on import (policy), not with the group statement
set policy-options policy-statement FROM-TRANSIT-B term 1 then local-preference 50
set policy-options policy-statement FROM-TRANSIT-B term 1 then accept
set protocols bgp group TRANSIT-B import FROM-TRANSIT-B
! FRR
bgp community-list standard CUST-BACKUP permit 65001:80
route-map FROM-CUSTOMER permit 10
match community CUST-BACKUP
set local-preference 80
route-map FROM-CUSTOMER permit 20
set local-preference 200
router bgp 65001
neighbor 192.0.2.1 remote-as 65010
address-family ipv4 unicast
neighbor 192.0.2.1 route-map FROM-CUSTOMER in
# GoBGP 4.11 (phase B, r1): global import policy, statements in order
[[policy-definitions]]
name = "in-tiers"
[[policy-definitions.statements]]
name = "customer-asks-backup"
[policy-definitions.statements.conditions.match-neighbor-set]
neighbor-set = "customers"
[policy-definitions.statements.conditions.bgp-conditions.match-community-set]
community-set = "cust-backup"
match-set-options = "any"
[policy-definitions.statements.actions]
route-disposition = "accept-route"
[policy-definitions.statements.actions.bgp-actions]
set-local-pref = 80
... customer 200, peer 150, transit 100 (same shape)
The Junos local-preference statement under a BGP group behaves differently from the Cisco default command. Juniper describes it as the "Preference to assign to routes that are advertised to the group or peer", and the documentation adds that the default 100 "applies at export time only".[10] Put on an iBGP group, it rewrites the LOCAL_PREF of everything you advertise to that group; it does not set the preference of routes you receive from an eBGP group. For an import decision on Junos, use an import policy as above. On Cisco IOS XR and IOS XE, bgp default local-preference changes the value given to paths that have none; IOS XR's reference notes that the default of 100 "allows you to easily define a particular path as less preferable than paths with no local preference attribute".[9]
Graceful shutdown: LOCAL_PREF 0 on purpose
RFC 8326 uses LOCAL_PREF for planned maintenance. Before you take an eBGP session down, you tag its routes with the well-known GRACEFUL_SHUTDOWN community 65535:0; routers that honour it set the LOCAL_PREF of those paths "to a low value", so traffic moves to other paths while the session is still up and nothing is lost during the actual shutdown. The RFC's BIRD example sets bgp_local_pref = 0.[7] FRR has it built in: neighbor graceful-shutdown marks all routes from that neighbour with the community and local-preference 0.[11] This only works if your import policy matches 65535:0 before the statements that set the tier values, the same ordering rule as the customer backup community above.
Common mistakes and troubleshooting
- Setting LOCAL_PREF on export to an eBGP neighbour. It is never sent, so nothing happens on the other side. To influence a neighbour, use its published communities (Design 3) or AS_PATH prepending and MED (part 18).[1]
- Changing LOCAL_PREF inside the AS. An internal router or route reflector that rewrites the value it received can disagree with the border router and loop traffic. RFC 4271 warns that local recomputation "may result in formation of persistent routing loops", and RFC 4456 says a route reflector SHOULD NOT modify LOCAL_PREF.[1][3]
- Overlapping tier values. If some transit routes get 150 for traffic engineering and peers also get 150, a TE change can quietly send traffic to a peer through a provider. Keep non-overlapping ranges per class.[13]
- Policy statement order. A general "customers get 200" statement placed before the community match makes customer communities and graceful shutdown useless. In the lab the backup statement was first; check the order in every vendor's policy language.
- Honouring LOCAL_PREF communities from everyone. Only customer sessions should be allowed to set your preference. Strip or ignore those communities from peers and transits, as Lumen documents for its network.[14]
- Forgetting the export side. Tiers without tag-and-filter still leak peer and transit routes to other peers and transits. Our phase A was a full route leak in four lines of adj-out. Consider RFC 9234 roles where your software supports them.[6]
- Expecting the backup to be visible everywhere. With Design 1 the backup route lives only on the backup border router. Troubleshoot on that router, and remember that failover includes one extra iBGP advertisement. Features such as BGP best-external or add-path exist to change this; they are outside this part.
- Weight overriding the AS policy. A WEIGHT set on one Cisco or FRR router wins before LOCAL_PREF is looked at, so that router alone ignores the tier policy. Check
show ip bgpfor non-zero weight first.[8][11]
FAQ
What is BGP local preference?
LOCAL_PREF (path attribute type 5) is a 32-bit number that tells every router inside one AS how much the AS prefers a route. Higher wins. It is set by import policy on the router that learns the route from an eBGP neighbour and is then carried to all iBGP peers, so the whole AS picks the same exit.
What is the default BGP local preference?
100 on Cisco IOS XE, IOS XR, Junos and FRR. Cisco treats a path without LOCAL_PREF as having the value of bgp default local-preference (100 unless changed); Junos handles a route received without it as 100 and applies the default when exporting into BGP.
Is local preference sent to eBGP neighbours?
No. RFC 4271 says a speaker MUST NOT send LOCAL_PREF to external peers (confederation sub-AS peers are the exception) and MUST ignore it if an external peer sends it. In our lab a LOCAL_PREF of 999 from an eBGP peer had no effect.
Local preference vs weight: which comes first?
On Cisco and FRR, WEIGHT is checked first, but it is local to one router and never advertised. LOCAL_PREF is the first step that is shared by the whole AS, and RFC 4271 does not define WEIGHT at all.
Does local preference beat a shorter AS path?
Yes. LOCAL_PREF is compared before AS_PATH length. In our lab a customer route with four ASNs and LOCAL_PREF 200 beat a peer route with two ASNs and LOCAL_PREF 150.
How can a customer change my local preference?
Only if you let it: you publish communities (for example 65001:80) and your import policy maps them to LOCAL_PREF values. Lumen, Arelion, Cogent and Orange publish such communities in their IRR objects; RFC 1998 described the method in 1996.
Should a route reflector change local preference?
No. RFC 4456 says a route reflector SHOULD NOT modify LOCAL_PREF (or NEXT_HOP, AS_PATH, MED) when reflecting, because routers inside the AS could then disagree about the best exit and loop.
Next in the series: part 10 covers the second well-known discretionary attribute, ATOMIC_AGGREGATE, and what it really signals after route summarisation.
Series hub: BGP in 26 Parts: From EGP to EVPN
Previous: BGP NEXT_HOP Attribute: How eBGP and iBGP Change It
Next: BGP ATOMIC_AGGREGATE Attribute: What It Signals After Route Summarisation (coming soon)
References
[1] Y. Rekhter, T. Li, S. Hares, RFC 4271: A Border Gateway Protocol 4 (BGP-4), January 2006: s.4.3 e), s.5.1.5, s.9.1, s.9.1.1.
[2] E. Chen, J. Scudder, P. Mohapatra, K. Patel, RFC 7606: Revised Error Handling for BGP UPDATE Messages, August 2015: s.7.5.
[3] T. Bates, E. Chen, R. Chandra, RFC 4456: BGP Route Reflection, April 2006: s.10.
[4] E. Chen, T. Bates, RFC 1998: An Application of the BGP Community Attribute in Multi-home Routing, August 1996: s.4, Tables 1-2.
[5] J. Snijders, J. Heasley, M. Schmidt, RFC 8195: Use of BGP Large Communities, June 2017: s.4.3.
[6] A. Azimov, E. Bogomazov, R. Bush, K. Patel, K. Sriram, RFC 9234: Route Leak Prevention and Detection Using Roles in UPDATE and OPEN Messages, May 2022: s.3.
[7] P. Francois, B. Decraene, C. Pelsser, K. Patel, C. Filsfils, RFC 8326: Graceful BGP Session Shutdown, March 2018.
[8] Cisco, Select BGP Best-path Algorithm, document 13753, updated 28 April 2026.
[9] Cisco, BGP Commands on Cisco IOS XR Software: bgp default local-preference.
[10] Juniper Networks, Local Preference for BGP Routes and CLI Explorer: local-preference (protocols bgp).
[11] FRRouting, BGP documentation (route selection, community to local-preference example, neighbor graceful-shutdown), read 1 December 2026.
[12] GoBGP, policy.md (set-local-pref, match-neighbor-set, match-community-set).
[13] M. Caesar, J. Rexford, BGP routing policies in ISP networks, IEEE Network 19(6), 2005.
[14] IRR aut-num objects queried 1 December 2026, 05:03 CET: AS1299 and AS5511 at whois.ripe.net, AS174 at whois.radb.net, AS3356 at whois.radb.net (source LEVEL3). Raw responses kept with the article sources.
[15] Network freak lab: GoBGP 4.11.0 routers r1-r4 (127.0.2.91-94) and raw Python BGP speakers C, P, I, X, T (127.0.2.95-99), phases A (no policy) and B (LOCAL_PREF policy), 1 December 2026, 05:04-05:07 CET. Configs, logs and captured bytes kept with the article sources.
Figures 1-8: Network freak, drawn from the sources above and our lab.
Try it: BGP Route Lookup: origin AS, AS paths and RPKI check - free, runs in your browser.
Related reading
- How BGP LOCAL_PREF Controls Outbound Exit Selection
- BGP Weight as Cisco's Local-Only Path Preference
- How BGP Best-Path Selection Picks a Route
- BGP Dual-ISP Edge Design: Redundancy, Traffic Engineering and Safe Filtering
- How to Control Inbound BGP Traffic: AS_PATH Prepending, MED and Provider Communities
- BGP Communities: no-export and Blackhole Routing in Practice
Comments
Post a Comment