Course contents

Module 3: Path SelectionLesson 3.3 (3 of 13 in this module)12 of 43 in the BGP course

Attribute: local preference

Two exits, one decision. Local preference is how a whole AS agrees on which door to use, and it is the tool you will reach for most often.

Advanced · 9 min read

You'll learn to explain LOCAL_PREF, set it with a route map to make one ISP primary, and read it in show ip bgp on both routers.

What LOCAL_PREF is

LOCAL_PREF is a well-known discretionary attribute that tells every router in one AS how much the AS prefers a route. The default is 100 and the highest value wins. It is compared after weight and before AS path length, so it overrides how far away a destination is.

It exists only inside an AS. The router that receives a route from an eBGP neighbour sets the value, iBGP passes it unchanged to the other routers, and it is stripped when a route leaves the AS.

Local preference chooses the exit for the whole AS
Local preference chooses the exit for the whole ASISP A, R1, R2 and ISP B in a row. R1 sets local preference 200 on routes from ISP A. R2 keeps the default 100 for routes from ISP B. iBGP carries local preference 200 from R1 to R2, so both routers leave through R1 and ISP A.Company AS 64500local-pref 200iBGP carries 200local-pref 100 (default)ISP AAS 64501R1RID 1.1.1.1R2RID 2.2.2.2ISP BAS 64502Both routers prefer the path through R1 and ISP AThe ISP B path stays in the table as the backup

On small screens, swipe sideways or focus the diagram and use the arrow keys.

LOCAL_PREF travels inside the AS, so one setting on R1 steers R2 as well. Weight would only have changed R1.

Why it solves what weight cannot

Weight is private to one router. Local preference rides inside the iBGP update, so every router learns the same number and reaches the same conclusion. That is why it is the standard way to say ISP A is primary and ISP B is the backup.

Weight stays on one router, local preference travels
Weight stays on one router, local preference travelsR1 and R2 are iBGP neighbours in AS 64500. R1 hears the route from ISP A, R2 hears it from ISP B. Setting weight 200 on R1 makes R1 prefer ISP A but R2 never sees the weight, so R2 still decides on its own. Setting local preference 200 on R1 is sent to R2 in the iBGP update, so both routers prefer the path through R1.ISP AAS 64501ISP BAS 64502AS 64500R1R2iBGPweight 200 on R1R1 prefers ISP AR2 never sees it and chooses alonelocal-preference 200 on R1sent to R2 inside the iBGP updateboth routers prefer the R1 exit

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Weight is Cisco-specific, local to the router and never advertised. Local preference is part of the BGP update inside the AS. Use weight for a single-router exception and local preference for an AS-wide decision.

Setting local preference

Set it on the router that receives the route from the neighbour, with an inbound route map. The route map can match everything, or only some prefixes.

route-map ISPA-IN permit 10 set local-preference 200 ! router bgp 64500 address-family ipv4 unicast neighbor 192.0.2.1 route-map ISPA-IN in end clear ip bgp 192.0.2.1 soft in

R1. Every route from ISP A is stored with local preference 200 and sent to R2 with that value. ISP B routes keep the default 100, so the whole AS leaves through ISP A while it is up.

router bgp 64500 bgp default local-preference 150

Sets the default for routes that no route map has changed. Use it when you want a whole router to prefer or avoid its own external paths.

How the value spreads
How the value spreadsOne router sets it, iBGP carries it.R1 receivesroute from ISP AR1 setslocal-preference 200iBGP sendsvalue goes to R2Both chooseexit through ISP A

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Both routers end up comparing the same number.

Different exits for different prefixes

Match prefixes in the route map to split traffic between providers. Prefixes that ISP A reaches better get 200 from ISP A, and prefixes that ISP B reaches better get 200 from ISP B. Each link carries its share and each is the backup for the other.

ip prefix-list VIA-A seq 5 permit 203.0.113.0/24 ip prefix-list VIA-B seq 5 permit 192.0.2.128/25 ! route-map ISPA-IN permit 10 match ip address prefix-list VIA-A set local-preference 200 route-map ISPA-IN permit 20 ! route-map ISPB-IN permit 10 match ip address prefix-list VIA-B set local-preference 200 route-map ISPB-IN permit 20

R1 and R2. Each route map raises the preference for its own prefix list and passes everything else at the default 100.

Reading it on both routers

Illustrative Cisco IOS XE output written for this lesson, not a router capture
R2#show ip bgp 203.0.113.0
BGP routing table entry for 203.0.113.0/24, version 11
Paths: (2 available, best #2, table default)
  64502
    192.0.2.5 from 192.0.2.5 (12.12.12.12)
      Origin IGP, metric 0, localpref 100, valid, external
  64501
    10.255.0.1 from 10.255.0.1 (1.1.1.1)
      Origin IGP, metric 0, localpref 200, valid, internal, best
R2 has its own external path through ISP B, but chooses the iBGP path from R1 because localpref 200 beats 100. Local preference is compared before the rule that prefers eBGP over iBGP.
How a Cisco router chooses one best path
How a Cisco router chooses one best pathTen rows. A path must first be valid with a reachable next hop. Then Cisco IOS XE compares weight, local preference, local origination, AS_PATH length, origin, MED, eBGP over iBGP, IGP metric to the next hop and finally the tie-breakers. The first difference decides.Gate: the path must be valid, with a reachable next hop and not filtered1Weighthighest wins (Cisco only, local to this router)2LOCAL_PREFhighest wins (shared inside the AS)3Locally originatedpreferred over paths learned from peers4AS_PATH lengthshortest wins5ORIGINlowest wins: IGP, then EGP, then incomplete6MEDlowest wins (same neighbouring AS by default)7eBGP over iBGPan external path beats an internal one8IGP metric to next hoplowest wins9Tie-breakersoldest eBGP path, lowest router ID, lowest neighbour IPFirst difference wins. Steps 1 and 2 are the ones you configure most often.

On small screens, swipe sideways or focus the diagram and use the arrow keys.

The comparison stops at the first step where the paths differ. Later steps are never reached for that prefix.

Mistakes to avoid

Common local preference mistakes
Common local preference mistakesWhy the policy sometimes does nothing.Set on the wrong routerEdge router must set it on receiptApply the route map inboundWeight still setWeight wins firstShow output has a weight fieldNo soft clearOld routes keep old valueclear ip bgp x.x.x.x soft inExpecting inbound effectIt only steers outboundUse prepending for inbound

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Check these in order before changing the value.
Splitting inbound traffic by prefix
Splitting inbound traffic by prefixYour AS announces two prefixes to ISP A and ISP B. 198.51.100.0/25 is announced to ISP A normally and prepended toward ISP B, so the internet prefers ISP A for it. 198.51.100.128/25 is announced to ISP B normally and prepended toward ISP A, so the internet prefers ISP B for it.InternetISP AAS 64501ISP BAS 64502Your edgeAS 64500198.51.100.0/25normal: preferred here198.51.100.128/25 prepended198.51.100.128/25normal: preferred here198.51.100.0/25 prepended

On small screens, swipe sideways or focus the diagram and use the arrow keys.

Each link carries one prefix as the preferred path and the other as the backup. Both prefixes stay reachable through both ISPs, so a failure moves traffic automatically.

Check your understanding

Predict · scenario 1

R1 sets local preference 200 on routes from ISP A. Which routers use that value?

Predict · scenario 2

R2 has an eBGP path with localpref 100 and an iBGP path from R1 with localpref 200. Which does R2 use?

Predict · scenario 3

Which statement about local preference is correct?

FAQ

What is the default local preference?
100 on Cisco IOS XE. The highest value wins.
Is local preference sent to other autonomous systems?
No. It is carried only in iBGP updates. It is removed when a route is sent to an eBGP neighbour.
Can local preference change how others reach me?
No. It controls how your AS sends traffic out. Inbound traffic is influenced with prepending, MED and more-specific prefixes.