BGP · · 4 min read

BGP AS-Path Prepending: When It Works and When It Doesn't

AS-path prepending is the go-to tool for influencing inbound traffic in BGP. The concept is simple: artificially lengthen the AS-path on your outbound advertisements to make that path less attractive at step 4 of the best path algorithm. But prepending is a blunt instrument — it works globally (affects all upstream ASes, not just your direct neighbor), it's unpredictable in how much traffic it actually shifts, and excessive prepending has real security implications.

How Prepending Works

When you prepend your own ASN to the AS-path, the route appears to be more hops away. Remote ASes that compare AS-path length (step 4 of best path) will prefer the shorter path through your other connection.

! Without prepending: AS-path seen by ISP-B's upstreams = "65020 65001"
! With 3x prepend:   AS-path seen by ISP-B's upstreams = "65020 65001 65001 65001 65001"

route-map PREPEND-TO-ISP-B permit 10
 set as-path prepend 65001 65001 65001
!
router bgp 65001
 neighbor 172.16.0.6 route-map PREPEND-TO-ISP-B out

Now routes advertised to ISP-B have an AS-path 3 hops longer than the same routes advertised to ISP-A. Upstream networks that see both paths should prefer the ISP-A path.

Important Rules

When Prepending Works

Prepending is effective when:

When Prepending Fails

Prepending does NOT work when:

Selective Prepending

Instead of prepending all routes to an ISP, you can prepend selectively:

ip prefix-list LOW-PRIORITY seq 10 permit 10.2.0.0/16
!
route-map SELECTIVE-PREPEND permit 10
 match ip address prefix-list LOW-PRIORITY
 set as-path prepend 65001 65001
!
route-map SELECTIVE-PREPEND permit 20
! No prepend for everything else
!
router bgp 65001
 neighbor 172.16.0.6 route-map SELECTIVE-PREPEND out

Only 10.2.0.0/16 gets prepended through ISP-B; other prefixes are advertised normally. This is useful when you want most traffic via ISP-B but want specific prefixes to prefer ISP-A.

Verification

! What ISP-B sees
R1-HQ# show ip bgp neighbors 172.16.0.6 advertised-routes
   Network          Next Hop         Metric LocPrf Weight Path
*> 10.1.0.0/16      172.16.0.5                        32768 65001 65001 65001 i
*> 10.2.0.0/16      172.16.0.5                        32768 i

Wait — that's wrong. The path shows "65001 65001 65001" but 10.2.0.0/16 should be the prepended one. Let me fix the example:

R1-HQ# show ip bgp neighbors 172.16.0.6 advertised-routes
   Network          Next Hop         Metric LocPrf Weight Path
*> 10.1.0.0/16      172.16.0.5                        32768 i
*> 10.2.0.0/16      172.16.0.5                        32768 65001 65001 i

ISP-B's perspective (note: the advertising AS 65001 is prepended to the front by ISP-B, then our prepends follow):

ISP-B-PE1# show ip bgp 10.2.0.0/16
  65001 65001 65001
    172.16.0.5 from 172.16.0.5 (1.1.1.1)
      Origin IGP, valid, external, best

The AS-path is now 65001 65001 65001 — the original plus two prepends. ISP-B's upstreams will see this as a 3-hop path, vs a 1-hop path through ISP-A.

Security Implications of Excessive Prepending

Every ASN you add to the prepend is another ASN an attacker can include in a forged AS-path to make a hijacked route look plausible. Long AS-paths also increase the BGP update message size and consume more memory in the global routing table. Keep prepends to 1-3 at most.

For stronger inbound traffic engineering, consider ISP community-based signaling (see BGP Communities) if your upstream supports it — many ISPs offer communities that set local-pref values on your routes, which is far more effective than prepending.

Troubleshooting

SymptomCauseFix
Prepending applied but traffic still coming through that ISPUpstream's local-pref overrides AS-path comparison; or hot potato routing in upstream's networkPrepending alone can't override local-pref. Contact upstream about community-based signaling, or advertise more-specific prefixes through the preferred ISP.
Routes rejected by upstream after prependingPrepended a foreign ASN instead of your own; or upstream has max-AS-path-length filteringOnly prepend your own ASN. Keep total AS-path under the upstream's limit (typically 50-100 hops, but some filter at lower values).
Prepending working for some destinations but not othersNormal — different remote ASes have different policies. Some may use local-pref, others may not compare AS-path.Prepending is inherently imprecise. For specific destinations, use communities or more-specific prefixes.

Key Takeaways

Read next

© 2025 Ping Labz. All rights reserved.