Course contents

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

Attribute: weight

Weight is the first thing a Cisco router compares and the only attribute no other router ever sees. When is that a feature, and when does it hide a design mistake?

Advanced · 9 min read

You'll learn to explain what weight is, set it on one router with a neighbour command or a route map, and say why it cannot steer the whole AS.

What weight is

Weight is a number from 0 to 65535 that a Cisco router attaches to every path in its own BGP table. It is never placed in a BGP UPDATE, so it exists only on the router where you set it. The path with the highest weight is the best path, and the comparison is made before any other attribute.

Paths the router originated with the network command, redistribution or aggregation start at 32768. Paths learned from a neighbour start at 0. That is why a locally originated route beats a learned route to the same prefix without any configuration.

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.

Where weight sits in the decision

Cisco IOS XE walks a fixed list of comparisons and stops at the first one that finds a difference. Weight is step 1, so if two paths have different weights nothing else is looked at, not local preference, not AS path length.

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.

Setting weight

There are two ways. The neighbour command sets one value for every route from that neighbour. A route map lets you match some routes and give them a different weight.

router bgp 64500 address-family ipv4 unicast neighbor 192.0.2.1 weight 300 end clear ip bgp 192.0.2.1 soft in

R1. Every route learned from ISP A at 192.0.2.1 gets weight 300. Routes from ISP B stay at 0, so R1 prefers ISP A for every prefix both can reach.

ip prefix-list WEB-NETS seq 5 permit 203.0.113.0/24 ! route-map ISPA-WEIGHT permit 10 match ip address prefix-list WEB-NETS set weight 300 route-map ISPA-WEIGHT permit 20 ! router bgp 64500 address-family ipv4 unicast neighbor 192.0.2.1 route-map ISPA-WEIGHT in end clear ip bgp 192.0.2.1 soft in

R1. Only 203.0.113.0/24 learned from ISP A gets weight 300. Sequence 20 permits everything else unchanged, so the rest of ISP A's routes are not dropped by the implicit deny.

The soft clear matters. Weight is applied when a route is received, so the new value only takes effect on routes that are processed again. A soft inbound clear asks the neighbour to resend, or replays stored copies, without closing the session.

How weight steers traffic

Weight changes where this router sends its outbound traffic, and nothing else. Traffic that enters the AS at another router follows that router's own choice. It has no effect on how the internet reaches you.

What a weight change does
What a weight change doesWeight is set on one router and read on that router only.Setweight 300 on R1CompareR1 checks weight firstChooseR1 exits via ISP AStopR2 is unaffected

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

No other router receives the value, so the effect stops at the router where it was configured.

That makes weight right for a narrow job: a remote-site router that must always use its local ISP, a lab test, or a temporary exception while you fix the real policy. For an exit choice the whole AS should follow, use local preference instead.

Reading weight in show output

Illustrative Cisco IOS XE output written for this lesson, not a router capture
R1#show ip bgp 203.0.113.0
BGP routing table entry for 203.0.113.0/24, version 14
Paths: (2 available, best #1, table default)
  64501
    192.0.2.1 from 192.0.2.1 (11.11.11.11)
      Origin IGP, metric 0, localpref 100, weight 300, valid, external, best
  64502
    192.0.2.5 from 192.0.2.5 (12.12.12.12)
      Origin IGP, metric 0, localpref 100, valid, external
The ISP A path shows weight 300 and is best. The ISP B path shows no weight, which means 0. Local preference is equal at 100, but it was never compared because weight already decided.

In the table form, show ip bgp prints a Weight column on the right. A value of 32768 marks a route this router originated.

Worked example: a stuck backup path after redistribution

A classic weight problem appears when a site learns the same prefix from two sources. R1 learns 198.51.100.0/24 over eBGP from the provider and, at the same time, an IGP route to it is redistributed into BGP on R2 inside the AS. A redistributed route is locally originated on R2, so it carries weight 32768 there. On R2 that path beats the iBGP-learned path from R1 at step 1, before local preference is ever looked at, so R2 keeps sending traffic out through the backup exit even though the primary exit is healthy.

The fix is not to raise local preference, because weight is compared first. Lower the weight of the redistributed path on R2 with a route map, so that the learned path wins and the redistributed one stays as a backup.

route-map REDIST-WEIGHT permit 10 set weight 0 ! router bgp 64500 address-family ipv4 unicast redistribute eigrp 100 route-map REDIST-WEIGHT end clear ip bgp * soft out

R2. Redistributed routes now enter the BGP table with weight 0 instead of 32768. The iBGP path from R1 can win on local preference, and the redistributed path is used only if that path disappears. Use a value such as 40000 instead when the redistributed path must win.

Both directions are valid. Which value you choose depends on whether the redistributed route is the primary or the backup path. The point of the example is that a locally originated path is not neutral: it starts with the highest default weight and wins unless you change it.

Mistakes to avoid

Common weight mistakes
Common weight mistakesFour ways weight causes surprises.Using it for AS-wide policyOther routers never see itUse local preferenceForgetting the soft clearOld routes keep their old weightclear ip bgp x.x.x.x soft inRoute map with no permit-allUnmatched routes are droppedAdd a final permit sequenceStale weight left behindOverrides later policyDocument and remove it

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

Each of these makes two routers in one AS disagree.

Check your understanding

Predict · scenario 1

R1 has weight 300 on ISP A routes and R2 has no weight configured. Where does traffic leave the AS?

Predict · scenario 2

Which paths start with weight 32768?

Predict · scenario 3

Weight and local preference differ. Which statement is correct?

FAQ

Is weight part of the BGP standard?
No. Weight is a Cisco-specific value kept in the local table. It is not in the UPDATE message, so other vendors and other routers do not have it.
What is the default weight?
Routes the router originated itself get 32768. Routes learned from a neighbour get 0. The highest weight wins.
Why not use weight everywhere?
Because it is local. Two routers with different weights can pick different exits for the same prefix, and that makes traffic hard to predict.