AS_PATH is the attribute that makes BGP a path-vector protocol. It records every network a route crossed, and it is also the lever you pull to nudge traffic toward one ISP.
Advanced · 9 min read
You'll learn to describe how AS_PATH grows and prevents loops, prepend your own AS to influence inbound traffic, and read paths in show ip bgp.
What AS_PATH records
AS_PATH is a well-known mandatory attribute. It is an ordered list of the autonomous systems a route has crossed, with the most recent AS first and the originating AS last. A router leaving an AS over eBGP adds its own AS number at the front.
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.
Two jobs: loops and distance
First, loop prevention. A router that finds its own AS number in a received path drops the route, because the route has already passed through its network. Second, distance. After weight and local preference, BGP prefers the path with the fewest AS numbers, so a shorter list wins.
What AS_PATH is used for
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Both decisions use the same list.
Path length counts AS hops, not routers or bandwidth. A path through one slow AS beats a path through two fast ones. That is why AS_PATH is a blunt but predictable measure.
Prepending to influence inbound traffic
You cannot choose how the internet sends traffic to you, but you can make one path look longer. AS-path prepending adds extra copies of your own AS number to routes sent to one provider. Networks with a choice then see a longer path through that provider and tend to use the other.
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.
ip prefix-list COMPANY-ONLY seq 5 permit 198.51.100.0/24
!
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, so most networks prefer the ISP A path.
Prepending step by step
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Prepend toward the provider you want as the backup.
Limits of prepending
Prepending is a request, not a command. A network whose local preference favours ISP B ignores path length entirely. Two or three copies are usually enough, because many networks have the same length difference in the other direction, and more copies add little. You can also prepend per prefix to split traffic between providers.
Splitting inbound traffic by prefix
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.
Reading AS_PATH
Illustrative Cisco IOS XE output written for this lesson, not a router capture
R2#show ip bgp 198.51.100.0
BGP routing table entry for 198.51.100.0/24, version 22
Paths: (2 available, best #1, table default)
64501 64500
192.0.2.1 from 192.0.2.1 (11.11.11.11)
Origin IGP, metric 0, localpref 100, valid, external, best
64502 64500 64500 64500 64500
192.0.2.5 from 192.0.2.5 (12.12.12.12)
Origin IGP, metric 0, localpref 100, valid, external
A remote router sees two paths to 198.51.100.0/24. The ISP A path is two AS numbers long. The ISP B path is five, because of the prepends, so the ISP A path wins at the AS path step.
Check your understanding
Predict · scenario 1
A router receives a route whose AS_PATH contains its own AS number. What does it do?
Predict · scenario 2
You want inbound traffic to prefer ISP A. What do you do to the routes sent to ISP B?
Predict · scenario 3
Which statement about AS_PATH is correct?
FAQ
Why does BGP drop a route with its own AS in the path?
That is the loop check. If the route has already been through this AS, accepting it again could create a forwarding loop, so the router discards it.
Does iBGP add to the AS_PATH?
No. The AS number is added only when a route leaves an AS over eBGP. Routers inside the AS see the path unchanged.
Can I prepend any AS number?
Prepend only your own AS. Adding another network number makes the path misleading and can break the other network's filters.