Course contents

Module 3: Path SelectionLesson 3.11 (11 of 13 in this module)20 of 43 in the BGP course

Controlling outbound traffic: weight and local preference

The company has two ISPs. ISP A is the better contract and ISP B is the backup. By default each router sends traffic to its own provider. How do you make every outbound packet leave through ISP A while it is healthy?

Advanced · 13 min read

You'll learn to make one provider the preferred exit for a whole AS with local preference, explain why weight only helps one router, and verify the choice on both routers.

Why the default choice is not what you want

In the course lab each router has one eBGP path to 203.0.113.0/24 and one iBGP path from its neighbour. All the early attributes tie, so the rule eBGP over iBGP decides: R1 leaves through ISP A and R2 leaves through ISP B. The company is using both providers equally, which may not match what it pays for.

The goal is simple: while ISP A works, both routers should send outbound traffic through it. If ISP A fails, the path through ISP B should take over without anyone logging in.

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.

Local preference is the right tool. It is compared second in the best-path order, it is shared with every iBGP peer, and a higher value wins. Setting 200 on the paths from ISP A makes them beat the default 100 everywhere in AS 64500.

Set local preference with a route map

A route map matches routes and sets attributes on them. Here we match the one prefix we expect from ISP A and set its local preference. A route map applied inbound also filters: anything that does not match a permit sequence meets the implicit deny and is rejected. So this route map replaces the earlier inbound prefix list on that neighbour.

Local preference route map
Local preference route mapMatch the routes, set the value, apply inbound.Matchroutes from ISP ASetlocal-preference 200Applyneighbor route-map inRefreshsoft clear or refresh

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

Higher local preference wins, and it is shared across the AS.
route-map ISPA-IN permit 10 match ip address prefix-list PROVIDER-ONLY set local-preference 200 router bgp 64500 address-family ipv4 unicast no neighbor 192.0.2.1 prefix-list PROVIDER-ONLY in neighbor 192.0.2.1 route-map ISPA-IN in exit-address-family

R1, global configuration mode. PROVIDER-ONLY is the exact 203.0.113.0/24 prefix list from the lab. Only R1 needs this change; R2 learns the value over iBGP.

Changing an inbound policy does not rewrite routes already accepted. Ask ISP A to send its routes again with a soft reset, which keeps the session up. The next lesson covers why this works.

clear ip bgp 192.0.2.1 soft in

R1, privileged EXEC mode. Re-applies the inbound policy to the routes ISP A sends again, without resetting the session.

Verify on both routers

Check R1 first, then R2. The point of the lesson is that R2 changed without being configured.

Check both ends
Check both endsThe change must appear on the router that sets it and on its iBGP peer.R1LocPrf 200, bestiBGP carries itto R2R2LocPrf 200, exit via R1

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

Check the value and the best-path marker on both.
Illustrative Cisco IOS XE output written for this lesson, not a router capture
R2#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>  198.51.100.0     0.0.0.0                  0         32768 i
 *>i 203.0.113.0      10.255.0.1               0    200      0 64501 i
 *                    192.0.2.5                0             0 64502 i
R2 now prefers the iBGP path from R1: the > and the i mark it, and LocPrf shows 200. The path through ISP B stays in the table with no local preference shown (it was learned over eBGP) and is the backup. R2 changed because R1 shared its local preference, not because anything was configured on R2.

Prove it with traffic: on R2, traceroute 203.0.113.1 source 198.51.100.3 should now cross R1 and ISP A instead of leaving through ISP B.

Weight: faster, but only for one router

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.

Weight is checked before local preference. It is a Cisco setting on one router, so use it when only that router needs an exception.

Weight and local preference
Weight and local preferenceWeight is local to one router and checked first. Local preference is shared across the AS.WeightCisco only, one routerNever advertisedChecked firstLocal preferenceStandard attributeShared by iBGPChecked secondvs

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

Use local preference for AS-wide design and weight for one-router overrides.
router bgp 64500 address-family ipv4 unicast neighbor 192.0.2.1 weight 300

R1: every path learned from ISP A gets weight 300 on R1 only. R2 is not affected, so a stray weight can leave the two routers disagreeing about the exit.

Sharing the load: a different exit for different destinations

One local preference for everything sends all outbound traffic through one provider and leaves the other link idle. If both links are paid for, you can split by destination: prefer ISP A for some destination prefixes and ISP B for the rest. The inbound route map matches the prefixes and sets a different value for each.

ip prefix-list VIA-ISPA seq 5 permit 203.0.113.0/24 ip prefix-list VIA-ISPA seq 10 permit 203.0.114.0/24 ! route-map FROM-ISPA permit 10 match ip address prefix-list VIA-ISPA set local-preference 200 route-map FROM-ISPA permit 20 set local-preference 100 ! route-map FROM-ISPB permit 10 match ip address prefix-list VIA-ISPA set local-preference 100 route-map FROM-ISPB permit 20 set local-preference 200 ! router bgp 64500 address-family ipv4 unicast neighbor 192.0.2.1 route-map FROM-ISPA in neighbor 192.0.2.5 route-map FROM-ISPB in

R1 and R2. The two listed destinations leave via ISP A. Everything else leaves via ISP B. Each link carries traffic, and each is the backup for the other, because the other provider's path is still in the table with a lower value.

Three ways to choose which routes to prefer
Three ways to choose which routes to preferWhat the route map can match on.Prefix listSpecific destinations you namePrecise, but you maintain the listAS-path filterEverything originated by or behindan AS, such as a cloud providerCommunityRoutes the provider has tagged,such as by region

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

Pick the match that stays correct as the internet changes.

How much of the internet table should you accept

How much of the internet to accept from a provider
How much of the internet to accept from a providerAccepting only a default route gives a very small table but no choice of exit. A default route plus partial routes gives a moderate table and some control. Accepting the full table gives complete control and needs the most memory and processing.Default route onlytable sizeProvider sends 0.0.0.0/0Tiny table, any routerNo say in which exitDefault plus partialtable sizeCustomer routes and a defaultModerate tableSome control per prefixFull tabletable sizeEvery internet prefixNeeds memory and CPUFull control of exits

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

The more routes you accept, the more precisely you can choose a path and the more your router has to carry. Match the choice to the router, not to habit.

The provider can send you three amounts of routing information, and the amount decides how much outbound control you have.

How much of the internet table should you accept
How much of the internet table should you acceptYou receive; Outbound control; Cost. Default route only: One exit per router, chosen by local preference on the default. No per-destination choice. Smallest tables Default plus selected prefixes: Per-destination choice for the prefixes you receive, default for the rest. Moderate Full internet table: Any destination, by prefix, AS path or community. Router memory for several hundred thousand routes per providerYou receiveOutbound controlCostDefault route onlyOne exit per router, chosen by localpreference on the default. Noper-destination choice.Smallest tablesDefault plus selectedprefixesPer-destination choice for theprefixes you receive, default for therest.ModerateFull internet tableAny destination, by prefix, AS pathor community.Router memory for several hundredthousand routes per provider

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

Read each row across: the left box names the item, the others describe it.

Most enterprise edges start with default only from each provider and local preference to rank the two defaults. Move to a partial or full table only when you need the control, and make sure the routers can hold it.

Proving the traffic moved

The BGP table shows the choice, not the packets. After a change, check three things, in this order: the winning path on each router, the routing table entry, and the actual path of a packet.

show ip bgp 203.0.113.0 show ip route 203.0.113.0 traceroute 203.0.113.10 source 198.51.100.1

R1 and R2. The BGP table shows the best path and local preference, the routing table shows what is installed, and a traceroute sourced from a company address shows the first hop is the provider you chose.

A test that proves failover
A test that proves failoverMove traffic, break the primary, restore it.BaselineTraceroute viaISP AFail AShut the linkCheckTraceroute nowvia ISP BRestoreTraffic returnsto ISP A

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

A backup path that has never carried traffic is only a theory.

What this does not do

Local preference changes your exit, not your entrance. Other networks still choose how to reach the company prefix, and that depends on what each ISP receives from you. Also remember the failure case: because the ISP B path stays in the table, the company keeps working if ISP A fails. Test it in the path-selection lab.

What outbound policy cannot do
What outbound policy cannot doLocal preference chooses your exit but does not change how traffic returns.DoesChooses your exitMoves your outbound trafficDoes notChange the return pathControl the ISP networkbut

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

Return traffic follows other networks decisions.

Technical reference: Cisco, BGP best path selection algorithm. Output above is illustrative.

Check your outbound policy

Predict · scenario 1

You set local preference 200 on R1 for ISP A routes. R2 still uses ISP B. What is the most likely cause?

Predict · scenario 2

After editing an inbound route map, show ip bgp still shows the old local preference. What should you do?

Predict · scenario 3

Which setting would let only R1 prefer ISP A without telling R2?

FAQ

Why set local preference on R1 and not on R2?
The preferred path is the one learned from ISP A, which R1 receives. R1 raises its local preference to 200 and shares that value with R2 over iBGP. R2 then prefers R1's path to its own ISP B path.
When would I use weight instead?
When only one router needs a preference and the rest of the AS should keep the default behaviour. Weight is checked first on Cisco routers but never leaves the router, so it is useful for a local exception and risky as an AS-wide policy.
Does this change what the ISPs send to us?
No. Local preference affects only how your AS chooses an exit. How other networks reach you depends on what you advertise, which is the next lesson.