Use it when a route is rejected because it already contains your own AS, when prepending does not move inbound traffic the way you expected, or when the path with the shorter AS_PATH still loses.
AS_PATH
1. show ip bgp <prefix> — AS_PATH per path (leftmost = neighbour AS).
2. Shorter AS_PATH wins after weight, LOCAL_PREF and local origin.
3. A router rejects paths containing its own AS (loop prevention).
path received (own AS not in AS_PATH) → inbound/outbound policy (prepend, as-path filter) → Weight, LOCAL_PREF and local origin equal? → shorter AS_PATH wins → best path → RIB → traffic
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
show ip bgp regexp <regexp>Show Commands
Read-only Cisco show commands for confirming state, narrowing a fault and interpreting the current boundary.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 First 30 seconds Verify boundary
Immediate answer: Inspect the full AS_PATH for every candidate prefix and separate loop-prevention from best-path preference.
Verification chain: received UPDATE → policy changes/prepending → AS_PATH → eligibility/loop check → best-path → RIB
Stop condition: A shorter AS_PATH is not automatically best when earlier decision factors or policy already select another path.
Step 2 Operational verification and known-good state Verify boundary
show ip bgp 203.0.113.0 255.255.255.0
show ip bgp regexp _65030$
show ip bgp regexp ^65010_
show ip bgp regexp ^$
The first shows the AS_PATH of every path for one prefix. The regular expressions filter the whole table: _65030$ lists routes originated by AS 65030, ^65010_ routes learned directly from AS 65010, and ^$ routes originated in your own AS. ^ is the start of the path, $ the end and _ a boundary between AS numbers.
Known-good: every path shows the ASes you expect in the order you expect, received paths never contain your own AS, and your prepends are visible on the receiving side.
Step 3 Verification and output interpretation Verify boundary
Inspect AS_PATH for representative prefixes before and after policy. Confirm that the expected peer advertisements contain the intended path and that the local best-path decision actually changed if that was the goal. For inbound-engineering changes such as prepending, verify from a remote or upstream perspective when possible because the local router cannot show how an external AS will rank the advertisement.
Step 4 Verification & troubleshooting Narrow the fault
1. show ip bgp <prefix> → the AS_PATH line above each path.
2. Before concluding that AS_PATH decided, compare Weight and LOCAL_PREF on the paths. Only if they are equal does length matter.
3. To check a prepend, look on the receiving side — the neighbour's show ip bgp <prefix> or a public looking glass. The local advertised-routes view may not show attributes set by an outbound route-map.
4. A route that is missing altogether: check whether its path would contain your own AS; such routes are rejected on arrival and never reach the table.
Step 5 Failure signatures and troubleshooting branches Narrow the fault
- The shorter AS_PATH loses. An earlier step decided — look at Weight and LOCAL_PREF.
- Prepending does not move inbound traffic. The upstream prefers the route by LOCAL_PREF, or traffic follows a more specific prefix announced on the other link.
- Routes from your other site are not received. Both sites use the same AS number; loop prevention drops the routes. Use
allowas-inor ask the provider foras-override. - A private AS number shows up beyond your provider. It was not removed on the way out; see
remove-private-as. - An unexpected AS appears in the path. The route takes a different transit than assumed, or someone upstream is leaking it.
Step 6 When the problem is really fixed Narrow the fault
- Each candidate path shows the expected AS_PATH.
- You can name the step that decides between the paths — AS_PATH length, or an earlier attribute.
- Prepends are confirmed on the receiving side.
- Inbound traffic enters on the intended link (traceroute from outside, interface counters).
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
AS_PATH length is compared only after Weight, LOCAL_PREF and local origination, so prepending can never beat a neighbour's LOCAL_PREF. It counts autonomous systems, not routers, distance or latency, and an AS_SET counts as one.
show ip bgp <prefix> → AS_PATH on every path (leftmost = neighbouring AS, rightmost = origin AS). show ip bgp regexp _65010_ → every route that passes through AS 65010. To confirm a prepend, look at the path on the receiving side (the neighbour or a looking glass).
ReferenceWhat it is2 sections · depth on demand
BGP scope — internal and external paths
AS_PATH exists on internal and external BGP routes. Ordinary eBGP propagation prepends the advertising AS; ordinary iBGP propagation within the AS leaves AS_PATH unchanged. The local ASN in a received path normally prevents inter-AS loops, but an internal reflection loop cannot be detected by AS_PATH alone. iBGP therefore needs its no-relay rule or RR originator/cluster protections. The retained eBGP path-manipulation examples do not imply that AS_PATH is an eBGP-only attribute.
What it is
ReferenceWhy it matters1 section · depth on demand
Why it matters
It is the attribute everyone knows — "shortest AS path wins" — and the one most often overestimated. On Cisco it is only checked after Weight, LOCAL_PREF and local origination, so a longer path wins whenever policy says so. Its real strength lies elsewhere: it is one of the few attributes that travel across the whole Internet, which makes prepending the main way to influence how other networks reach you. And its loop-prevention rule explains why some routes are dropped without any message.
ReferenceImportant terms & boundaries7 sections · depth on demand
Key points
- Toward an eBGP neighbour the sender adds its own AS at the front; over iBGP the list is not changed.
- Read it right to left: the rightmost AS originated the prefix, the leftmost is the neighbour you learned it from.
- A router rejects a route from an eBGP neighbour if its own AS is already in the list.
- Shorter wins — after Weight, LOCAL_PREF and local origination.
- Length counts autonomous systems, not routers, distance or delay. An AS_SET
{…}counts as one. - Prepend only your own AS, outbound:
set as-path prepend 65000 65000. - Match paths with regular expressions:
show ip bgp regexp …andip as-path access-list.
In depth
AS_PATH lists the autonomous systems a route has passed through
Each eBGP speaker prepends its own AS number when it advertises a route. AS_PATH does two jobs: loop prevention (a router rejects routes containing its own AS) and path selection. In Cisco's best path order, shorter AS_PATH is step 4, after weight, local preference and locally originated routes.
R1# show ip bgp regexp _64520$
Network Next Hop Metric LocPrf Weight Path
*> 203.0.113.0/24 192.0.2.5 0 0 64511 64520 i
* 192.0.2.1 0 0 64510 64530 64520 i
R1(config)# route-map PREPEND-OUT permit 10
R1(config-route-map)# set as-path prepend 64500 64500 64500
R1(config)# router bgp 64500
R1(config-router)# neighbor 192.0.2.9 route-map PREPEND-OUT out
Documented points from Cisco's best path document
| Point | Detail |
|---|---|
| AS_SET | Counts as one AS, however many it contains |
| Confederation segments | Not counted in the length |
bgp bestpath as-path ignore | Skips the AS_PATH step (hidden command) |
Uses
| Use | How |
|---|---|
| Make an inbound path less preferred | Prepend your own AS on that link (above) |
| Filter routes from or to specific ASes | ip as-path access-list with regular expressions |
| Detect a route leak | Unexpected ASes in the path |
Prepending limits
Prepending affects only networks that compare AS_PATH. Neighbours that set LOCAL_PREF or weight override it. Many providers also prefer customer routes by local preference, so prepending towards a provider changes less than you'd expect. Prepending more than a few times rarely adds anything.
Common regular expressions
| Expression | Matches |
|---|---|
^$ | Routes originated in your own AS |
^64510_ | Learned directly from AS 64510 |
_64520$ | Originated by AS 64520 |
_64520_ | AS 64520 anywhere in the path |
Documented example, not captured output.
Platform, version and operating-envelope scope
Cisco IOS / IOS XE first; best-path tie breakers and command output vary by release and feature set.
Quick reference
AS_PATH lists the autonomous systems a route has traversed, newest first. BGP prefers shorter AS_PATHs and drops routes containing its own AS. Operators prepend their own AS several times to make a path less attractive for inbound traffic.
route-map PREPEND-OUT permit 10
set as-path prepend 65010 65010 65010
router bgp 65010
address-family ipv4 unicast
neighbor 192.0.2.1 route-map PREPEND-OUT out
show bgp ipv4 unicast regexp _64500$
Documented example, not captured output.
AS_PATH regular expressions (_64500$ = originated by AS 64500) are useful in filters and show commands.
Mechanics and state ownership
When a router advertises a route to a neighbour in another AS, it puts its own AS number at the front of the list. Inside an AS nothing is added, so the length of the list counts AS hops, not routers. A route you originate yourself has an empty path locally and carries just your AS once it has left.
The same list prevents loops between autonomous systems: a router that finds its own AS in a received path knows the route has already been through its AS and drops it. This is why two sites that use the same AS number and connect through a provider do not accept each other's routes unless allowas-in is configured (or the provider rewrites the path with as-override).
Prepending makes a path look longer by repeating your own AS. It can only make a path less attractive, and only for networks that reach the AS_PATH step with everything else equal. A neighbour that prefers customer routes through LOCAL_PREF will not be moved by any number of prepends, and a more specific prefix announced elsewhere wins before BGP best path is even consulted.
State model and selection mechanics
Each eBGP advertisement normally prepends the advertising AS to AS_PATH, building a path-history attribute as the route crosses AS boundaries. A router normally rejects a route containing its own ASN, providing inter-AS loop prevention. During best-path selection, a shorter AS_PATH is commonly preferred after higher-priority local policy attributes. AS_SET/confederation details can affect interpretation, so the visible string should be read as a BGP policy attribute rather than a literal packet-by-packet physical path trace.
Limits and common misconceptions
AS_PATH length is not physical hop count, latency or bandwidth. An AS may contain a large internal topology, and policy can prepend the same ASN multiple times. A shorter AS_PATH can lose to LOCAL_PREF or other earlier decision criteria, so “shortest AS path should win” is only true when higher-priority attributes do not decide first.
ReferenceConfiguration & state1 section · depth on demand
Policy and configuration model
Use AS_PATH policy deliberately. Prepending the local ASN can make a route less attractive to remote networks, but remote LOCAL_PREF or other upstream policy can override that signal. Filters can match AS sequences for acceptance or advertisement policy; such expressions should be narrowly scoped and documented because an overly broad AS-path regex can affect far more prefixes than intended.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Lab addressing; local AS 65000; eBGP neighbours already Established; route-refresh supported.
route-map PREPEND-OUT permit 10
set as-path prepend 65000 65000
!
router bgp 65000
address-family ipv4 unicast
neighbor 192.0.2.6 route-map PREPEND-OUT out
!
! then: clear ip bgp 192.0.2.6 soft outExpected output
show ip bgp 203.0.113.0 255.255.255.0Expected state: Both paths valid with equal Weight and LOCAL_PREF; the path with one AS in AS_PATH is best.
BGP routing table entry for 203.0.113.0/24
Paths: (2 available, best #1, table default)
65010
192.0.2.2 from 192.0.2.2 (2.2.2.2)
Origin IGP, metric 0, localpref 100, valid, external, best
65020 65030 65010
192.0.2.6 from 192.0.2.6 (3.3.3.3)
Origin IGP, metric 0, localpref 100, valid, external
! Illustrative output, not captured Evidence.The line above each next hop is the AS_PATH. Path 1 crosses one AS, path 2 three; LOCAL_PREF is equal, so AS_PATH length decides. Both paths end in 65010, the AS that originated the prefix.Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Routing → BGP → eBGP → AS_PATH. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.rfc-editor.org/rfc/rfc4271.html · confidence 94%Quick lookup tables
AS_PATH · routing reference
Compact path-selection and evidence boundaries for fast lookup.
| Observation | Meaning |
|---|---|
| ASN sequence | Inter-AS path history |
| Own ASN present | Loop-prevention trigger by default |
| Prepending | Policy signal, not physical hops |
| Shorter path | Preference only after earlier criteria |
AS_PATH operational reference
Topic-specific bounded interpretation: known-good BGP state, suspicious signatures and the next technical proof boundary.
| Boundary | Known-good for AS_PATH | Suspicious signature | Next proof |
|---|---|---|---|
| Session/input | Correct peer, AF and prefix context | Transport, FSM or prefix eligibility disagrees | Peer detail and exact prefix |
| Attribute/policy | AS_PATH as both inter-AS loop-prevention state and a policy-visible path attribute whose sequence length and manipulation can influence best-path selection matches intended policy | unexpected local-AS loop rejection, excessive or missing prepends, an apparently shorter AS_PATH losing because a higher-priority attribute decided first, policy matching the wrong ASN expression, or operators assuming AS_PATH length represents latency or actual router hops | Compare candidate paths and policy |
| Route/forwarding | Expected best path reaches RIB/FIB | BGP state exists but installed path disagrees | RIB/FIB/CEF and next-hop proof |
| Closure | Original test passes for explained reason | Symptom moved, was bypassed or state was forced | Regression/failover test |