Course contents

Module 3: Path SelectionLesson 3.4 (4 of 13 in this module)13 of 43 in the BGP course

Attribute: AS_PATH and prepending

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
The AS path grows by one AS at every eBGP hopAS 64503 originates 203.0.113.0/24 with an empty AS path inside its own AS. It sends the route to AS 64501, which sees AS path 64503 and adds its own number when passing it to AS 64500, which sees AS path 64501 64503.Prefix 203.0.113.0/24AS 64503Originates the prefixAS_PATH: (empty)AS 64501ISP AAS_PATH: 64503AS 64500Your companyAS_PATH: 64501 64503UPDATEUPDATEIf AS 64500 saw 64500 inside the path, it would drop the route

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
What AS_PATH is used forOne attribute, two decisions.Loop checkOwn AS in the path means dropApplied on receiptDistanceFewer AS numbers winStep 4 of best-path selectionFilteringMatch with regular expressionsApplied with filter-list

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
Prepending makes one path look longer to the rest of the internetA remote network in AS 64510 hears the company prefix through ISP A with AS_PATH 64501 64500, length 2, and through ISP B with AS_PATH 64502 64500 64500 64500, length 4, because the company prepended its own AS twice on the ISP B session. The shorter path through ISP A wins.Remote networkAS 64510ISP AAS 64501ISP BAS 64502AS_PATH: 64501 64500length 2, preferredAS_PATH: 64502 64500 64500 64500length 4, less attractiveCompanyAS 64500set as-path prepend 64500 64500(on the session to ISP B)

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
Prepending step by stepMake the backup path longer.Matchyour own prefixPrepend64500 three more timesSendtoward ISP B onlyResultlonger path via ISP B

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
Splitting inbound traffic by prefixYour AS announces two prefixes to ISP A and ISP B. 198.51.100.0/25 is announced to ISP A normally and prepended toward ISP B, so the internet prefers ISP A for it. 198.51.100.128/25 is announced to ISP B normally and prepended toward ISP A, so the internet prefers ISP B for it.InternetISP AAS 64501ISP BAS 64502Your edgeAS 64500198.51.100.0/25normal: preferred here198.51.100.128/25 prepended198.51.100.128/25normal: preferred here198.51.100.0/25 prepended

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.