AS Path Prepending: Traffic Engineering with BGP
Learn how AS path prepending works for inbound traffic engineering, its limitations, and when to use alternative approaches.
What Is AS Path Prepending?
AS path prepending is a BGP traffic engineering technique where you artificially lengthen the AS path for a route announcement. Since BGP prefers shorter AS paths, prepending makes a route less attractive to remote networks, steering traffic toward your other links.
Without prepending:
Route via Provider A: [64512] 203.0.113.0/24 (path length: 1)
Route via Provider B: [64512] 203.0.113.0/24 (path length: 1)
With prepending on Provider B:
Route via Provider A: [64512] 203.0.113.0/24 (path length: 1)
Route via Provider B: [64512 64512 64512] 203.0.113.0/24 (path length: 3)
Result: Most networks prefer Provider A (shorter path).
Configuration Examples
# Cisco IOS: Prepend 2x on announcements to Provider B
route-map PREPEND-TO-PROVIDER-B permit 10
set as-path prepend 64512 64512
router bgp 64512
neighbor 10.0.0.2 route-map PREPEND-TO-PROVIDER-B out
# Junos: Prepend 3x
policy-statement PREPEND-3X {
then {
as-path-prepend "64512 64512 64512";
}
}
protocols bgp group PROVIDER-B export PREPEND-3X
# BIRD: Prepend 2x
filter export_provider_b {
bgp_path.prepend(64512);
bgp_path.prepend(64512);
accept;
}
How Many Times to Prepend?
| Prepend Count | Typical Effect |
|---|---|
| 1x | Mild preference shift; many networks ignore |
| 2x | Moderate shift; effective for most cases |
| 3x | Strong preference; almost universal effect |
| 4x+ | Diminishing returns; looks unprofessional |
Never prepend more than 3 times. Beyond that, there is no measurable benefit, and excessively long AS paths can trigger route filtering (some networks reject paths longer than 50 ASes).
Limitations of Prepending
Prepending is a blunt instrument with significant limitations:
- Local preference wins -- If a remote network has set
local-preferencefor your routes, prepending is ignored (local-pref is evaluated before AS path length). - Affects all traffic -- You cannot selectively prepend for specific source networks.
- Global impact -- Prepending to one provider affects how all networks worldwide see your routes through that provider.
- Not deterministic -- You cannot guarantee where traffic will enter your network.
Better Alternatives
| Technique | Granularity | Complexity |
|---|---|---|
| BGP communities | Per-provider policy | Medium |
| Selective announcements | Per-prefix | Medium |
| More-specific prefixes | Per-subnet | Low |
| MEDs | Between two ASes | Low |
| Anycast | Geographic | High |
Using Communities Instead
Most transit providers support action communities that set local preference within their network:
# Instead of prepending, use community to lower preference at Provider B
route-map DEPREF-AT-B permit 10
set community 3356:90 # Lumen: set local-pref to 90
# At Provider A, set high preference
route-map PREFER-AT-A permit 10
set community 174:120 # Cogent: set local-pref to 120
Communities are more effective than prepending because they influence local-preference, which is evaluated before AS path length.
When Prepending Makes Sense
Despite its limitations, prepending is appropriate when:
- Your upstream does not support communities
- You need a quick, temporary traffic shift
- You want a simple backup/primary configuration
- You are at an IXP with no community support