R1 has two paths to 203.0.113.0/24 and can install only one. What information does BGP have to choose between them? Everything it knows is carried in path attributes, so let's learn to read them.
Advanced · 13 min read
You'll learn to name the main BGP path attributes, say which are well-known or optional and transitive or not, and read them in show ip bgp output.
A route is a prefix plus a description of its journey
A BGP UPDATE message carries two things: the destinations, called NLRI (network layer reachability information), and a set of path attributes that describe how to get there. One set of attributes applies to every prefix listed beside it. BGP has no metric like OSPF cost. It compares attributes.
One UPDATE: path attributes plus the prefixes they describe
On small screens, swipe sideways or focus the diagram and use the arrow keys.
A teaching view, not a byte-accurate capture. The attributes travel once and apply to every prefix listed beside them.
BGP chooses paths by comparing attributes, not by adding up link costs. To steer traffic you change an attribute on a route, so you need to know which attributes exist and who can see them.
Four categories, two questions
Every attribute answers two questions. Must every BGP router recognise it (well-known) or may a router not know it (optional)? And if a router does not recognise it, does it pass it on (transitive) or drop it (non-transitive)? Combining the answers gives four categories.
The four kinds of BGP path attribute
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Well-known means every BGP router must recognise the attribute. Transitive means a router that does not recognise it passes it on.
How far each attribute travels
Before the detail, one picture. Most confusion about attributes comes from expecting one to reach further than it does.
How far each attribute travels
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Pick the attribute whose reach matches what you want to influence: one router, your whole AS, a neighbour, or everyone downstream.
The rule behind every traffic decision
A route advertisement and the traffic that follows it move in opposite directions. Your neighbour tells you about 203.0.113.0/24, and you send packets to it. So there are two separate jobs, and each uses different attributes.
Routes flow one way, traffic flows the other
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Every BGP traffic-engineering decision starts with this question: am I changing what I hear, or what I tell?
Outbound traffic (you send): you control it fully. Change how you rank the routes you receive: weight on one router, LOCAL_PREF for the whole AS.
Inbound traffic (you receive): you can only influence it, because other networks make the decision. Change what you advertise: AS_PATH prepending, MED, communities the provider honours, and more-specific prefixes.
The rest of the lesson takes each attribute in turn: what it is, how a router uses it, and how you use it to move traffic. All examples use the course network: the company (AS 64500) has R1 connected to ISP A (192.0.2.1, AS 64501) and R2 connected to ISP B (192.0.2.5, AS 64502), and the company owns 198.51.100.0/24.
Weight: steer one router
What it is. A Cisco-only number from 0 to 65535, kept on the router and never sent. Routes the router originated get 32768, everything else 0. It is the first value compared, and the highest wins.
How it influences traffic. Outbound only, and only for traffic that passes through that router. Use it when one router needs a different exit from the rest of the AS, for example a router at a remote site that should always use its local ISP.
route-map ISPA-WEIGHT permit 10
set weight 300
!
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. Every route from ISP A gets weight 300 on R1 only. A one-line alternative is neighbor 192.0.2.1 weight 300.
Weight is not shared
On small screens, swipe sideways or focus the diagram and use the arrow keys.
This is why weight is a poor tool for a policy the whole AS should follow.
LOCAL_PREF: steer the whole AS
What it is. A number carried in iBGP that says how much this AS prefers a route. Default 100, highest wins. It is compared second, after weight, so an unset weight never interferes.
How it influences traffic. Outbound, for every router in the AS at once. The edge router that receives the route sets the value, iBGP carries it to the others, and all of them pick the same exit. It is the standard tool for "ISP A is primary, ISP B is backup".
Local preference chooses the exit for the whole AS
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.
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. Routes from ISP A now carry local preference 200. ISP B routes keep 100, so R1 and R2 both leave through ISP A while it is up.
You can set different values for different prefixes, which gives you load sharing: send traffic for some destinations out of ISP A and the rest out of ISP B, by matching prefixes in the route map.
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
On R2 the path through ISP A (learned from R1) has localpref 200 and wins, even though R2's own ISP B path is external. LOCAL_PREF is compared before eBGP over iBGP.
AS_PATH: how routes are measured, and prepending
What it is. The list of autonomous systems a route crossed, newest first. It prevents loops and, after weight and LOCAL_PREF, it is the main measure of distance: the shortest path wins.
The AS path grows by one AS at every eBGP hop
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Each AS prepends its own number when it advertises a route to an eBGP neighbour. A router that finds its own AS number in a path drops the route, which is how BGP prevents loops.
An AS adds its number only when the route leaves it over eBGP. Over iBGP the path does not change.
How it influences traffic. Inbound. Other networks compare path lengths, so if you make the path through ISP B look longer, networks that have a choice send their traffic through ISP A. You do this by adding your own AS number several times to the paths you advertise to ISP B.
Prepending makes one path look longer to the rest of the internet
On small screens, swipe sideways or focus the diagram and use the arrow keys.
The company adds copies of its own AS number on the ISP B session only. Remote routers compare AS_PATH length before they look at anything the company cannot influence.
route-map ISPB-OUT permit 10
match ip address prefix-list COMPANY-ONLY
set as-path prepend 64500 64500 64500
!
router bgp 64500
address-family ipv4 unicast
neighbor 192.0.2.5 route-map ISPB-OUT out
end
clear ip bgp 192.0.2.5 soft out
R2. ISP B and its customers now see 64500 four times in the path to 198.51.100.0/24 instead of once.
There is a second, reverse use: you can also filter by AS_PATH with an AS-path access list, to accept or reject routes based on who originated them or which ASes they crossed. That is covered in the filtering lesson.
MED: ask a neighbour to use one link
What it is. Multi-exit discriminator, shown as metric. A number you attach to routes you advertise to a neighbouring AS to suggest which of several links into your network it should use. Lower wins. A route with no MED counts as 0 on IOS.
How it influences traffic. Inbound, and only in one situation: you have two or more links to the same neighbouring AS. By default a router compares MED only between paths from the same neighbouring AS, and the neighbour does not pass it on. With two different ISPs, MED does nothing useful.
MED works with one neighbouring AS, not across two
On small screens, swipe sideways or focus the diagram and use the arrow keys.
MED is a hint from one AS to one neighbouring AS. It cannot choose between two different providers.
! On R1 (preferred entry point)
route-map TO-ISPA-MED permit 10
set metric 50
!
router bgp 64500
address-family ipv4 unicast
neighbor 192.0.2.1 route-map TO-ISPA-MED out
! On R3 (backup entry point, second link to ISP A)
route-map TO-ISPA-MED permit 10
set metric 100
!
router bgp 64500
address-family ipv4 unicast
neighbor 192.0.2.9 route-map TO-ISPA-MED out
Two company routers, both connected to ISP A. ISP A compares 50 and 100 and sends traffic for the company prefix in through R1. R3 is a hypothetical second router, added here for this example.
Communities: ask the provider to do it for you
What it is. A tag, written like 64501:80, attached to a route. On its own it does nothing. A router that sees the tag can match it in a route map and act.
How it influences traffic. Mostly inbound, by borrowing the provider's own policy. Large providers publish a list of communities customers can attach: lower my local preference inside your network, prepend towards a given peer, do not announce to a region. That reaches inside networks you cannot configure.
A provider community changes the provider's choice
On small screens, swipe sideways or focus the diagram and use the arrow keys.
The community values are defined by each provider. 64501:80 is an example, not a standard.
route-map TO-ISPA permit 10
match ip address prefix-list COMPANY-ONLY
set community 64501:80
!
router bgp 64500
address-family ipv4 unicast
neighbor 192.0.2.1 send-community
neighbor 192.0.2.1 route-map TO-ISPA out
end
clear ip bgp 192.0.2.1 soft out
R1. 64501:80 is a hypothetical provider community meaning lower the local preference to 80 for this route. IOS does not send communities unless send-community is configured on the neighbour.
More-specific prefixes: the strongest inbound tool
None of the attributes above matter if a router has a route that is more specific, because the routing table looks for the longest prefix match before any BGP comparison. If you advertise 198.51.100.0/25 to ISP A and 198.51.100.128/25 to ISP B, and the /24 to both, traffic for each half goes through the provider that holds its /25, whatever the attributes say.
Splitting a prefix steers inbound traffic
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Both ISPs also hear the /24, so if one link fails the other still carries everything.
NEXT_HOP and ORIGIN: usually correctness, rarely policy
NEXT_HOP is the address the router forwards to. Over eBGP the advertiser sets it to itself. Over iBGP it is not changed, which causes a classic fault.
NEXT_HOP: eBGP changes it, iBGP does not
On small screens, swipe sideways or focus the diagram and use the arrow keys.
The next hop is the address the router forwards packets to. A path whose next hop is unreachable is not valid, so it is never chosen as best.
As a traffic tool, next hop works indirectly: after the choice between paths is made, the IGP cost to the next hop breaks ties. Setting the next hop with a route map (set ip next-hop) is possible but rare, and it silently sends traffic somewhere the AS path did not suggest. Treat it as a last resort.
ORIGIN records how the route entered BGP and ranks below path length. It matters only when everything above ties, so it is a weak traffic tool. You can set it with set origin incomplete to make one path lose a tie, but prefer LOCAL_PREF or prepending.
The three ORIGIN values in order of preference
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Seen as the code before the path in show ip bgp.
Choosing the right attribute for the goal
Choosing the right attribute for the goal
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.
When two of these disagree, the best-path order settles it. Weight and LOCAL_PREF are compared first, so they override everything an outsider does to your advertisements.
BGP best-path order on Cisco IOS XE
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.
Summary of the main attributes
What each common attribute does
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Attributes are the vocabulary of policy.
Summary of the main attributes
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.
Reading the attributes of one prefix
The summary table hides most attributes. Ask for one prefix to see them all. This is R1 in the course network, which learned 203.0.113.0/24 from ISP A over eBGP and from R2 over iBGP.
From the command output to meaning
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Read from the top: the path, the next hop, then the numbers that decided the choice.
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 4
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, valid, external, best
64502
10.255.0.2 from 10.255.0.2 (2.2.2.2)
Origin IGP, metric 0, localpref 100, valid, internal
Each block is one path. The bare number line is its AS_PATH. The next line gives NEXT_HOP, then the neighbour it came from and that neighbour's router ID in brackets. The last line packs ORIGIN, MED (shown as metric), LOCAL_PREF and the flags: valid means the next hop is reachable, external or internal tells you the session type, and best marks the winner.
Here the paths tie on origin, metric and local preference. The AS_PATH lengths are also equal at one AS each, so the next comparison in the best-path order, external over internal, decides. That order is the next lesson.
Where attribute questions go wrong
Expecting LOCAL_PREF to cross an AS border. It is sent only to iBGP peers. If an eBGP neighbour sends one, the receiving router ignores it. To influence another AS you use AS_PATH or MED, and those are covered in the inbound path-control lesson.
Three attribute misunderstandings
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Know which attributes cross AS borders and which stay inside.
Treating MED as a general-purpose steering tool. MED is compared only between paths from the same neighbouring AS by default, and the receiving AS does not pass it onward. It is a hint, not an instruction.
Forgetting that iBGP keeps the next hop. A path can arrive at R2 with a next hop R2 cannot reach and show no valid flag. The attribute is fine; the router simply cannot use the path.
Technical references: RFC 4271 (BGP-4) defines the attributes and their categories. Output above is illustrative, written for this lesson.
Check your attribute knowledge
Predict · scenario 1
R1 sets local preference 200 on routes from ISP A. Which routers hear that value?
Predict · scenario 2
Which attribute is a router most likely to drop when it does not recognise it?
Predict · scenario 3
show ip bgp shows a path without the valid flag and with next hop 192.0.2.1 on R2. Which attribute is the problem?
Predict · scenario 4
You want other networks to prefer ISP A when sending traffic to your prefix. Where do you configure AS_PATH prepending?
Predict · scenario 5
You have one link to ISP A and one to ISP B and set MED 50 and 100 respectively. What is the effect?
Predict · scenario 6
R1 has weight 300 on ISP A routes. R2 has only default weight and LOCAL_PREF 200 set by R1. Which statement is true?
FAQ
Is weight a BGP attribute?
No. Weight is a Cisco-specific value kept on one router. It is never sent in an UPDATE, so it cannot influence any other router. It is still the first thing Cisco IOS XE compares when it chooses a best path.
Why does a router drop an unknown optional non-transitive attribute?
Non-transitive means the attribute applies only to the next hop of the path. A router that does not understand it has no safe way to act on it, so it does not pass it along. An unknown optional transitive attribute is passed on with a flag showing a router did not recognise it.
Does a router change attributes when it passes a route on?
Yes. Leaving an AS, a router adds its AS number to AS_PATH and normally sets NEXT_HOP to itself. Inside an AS, iBGP leaves both unchanged by default, which is why next-hop-self exists.