AS Path Prepending
Make one advertisement less attractive to a neighboring AS by lengthening its AS sequence, while recognizing that earlier remote policy can still win.
Two advertisements
R1 and R3 are separate speakers in AS 65010, both originating the same test /24 to R2 in AS 65020. R2 is the decision point. There is no internal peering or shared LAN between the originators in this isolated lab.
| Link | First endpoint | Second endpoint |
|---|---|---|
| R1–R2 | R1 GigabitEthernet1: 192.0.2.1/30 | R2 GigabitEthernet1: 192.0.2.2/30 |
| R2–R3 | R2 GigabitEthernet2: 192.0.2.5/30 | R3 GigabitEthernet1: 192.0.2.6/30 |
Complete baseline configurations
R1
hostname R1
ip cef
interface Loopback0
ip address 10.255.0.1 255.255.255.255
exit
interface Loopback10
ip address 198.51.100.1 255.255.255.0
exit
interface GigabitEthernet1
ip address 192.0.2.1 255.255.255.252
no shutdown
exit
router bgp 65010
bgp router-id 10.255.0.1
no bgp default ipv4-unicast
neighbor 192.0.2.2 remote-as 65020
address-family ipv4 unicast
no auto-summary
neighbor 192.0.2.2 activate
network 198.51.100.0 mask 255.255.255.0
exit-address-family
endR2
hostname R2
ip cef
interface Loopback0
ip address 10.255.0.2 255.255.255.255
exit
interface GigabitEthernet1
ip address 192.0.2.2 255.255.255.252
no shutdown
exit
interface GigabitEthernet2
ip address 192.0.2.5 255.255.255.252
no shutdown
exit
router bgp 65020
bgp router-id 10.255.0.2
no bgp default ipv4-unicast
neighbor 192.0.2.1 remote-as 65010
neighbor 192.0.2.6 remote-as 65010
address-family ipv4 unicast
no auto-summary
neighbor 192.0.2.1 activate
neighbor 192.0.2.6 activate
exit-address-family
endR3
hostname R3
ip cef
interface Loopback0
ip address 10.255.0.3 255.255.255.255
exit
interface Loopback10
ip address 198.51.100.3 255.255.255.0
exit
interface GigabitEthernet1
ip address 192.0.2.6 255.255.255.252
no shutdown
exit
router bgp 65010
bgp router-id 10.255.0.3
no bgp default ipv4-unicast
neighbor 192.0.2.5 remote-as 65020
address-family ipv4 unicast
no auto-summary
neighbor 192.0.2.5 activate
network 198.51.100.0 mask 255.255.255.0
exit-address-family
endR2# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
*> 198.51.100.0/24 192.0.2.1 0 0 65010 i
* 192.0.2.6 0 0 65010 iPrepend your AS
On R1, prepend two extra copies of its own AS only to the target prefix exported to R2. The ordinary external advertisement adds one more copy.
ip prefix-list TARGET seq 5 permit 198.51.100.0/24
route-map LONGER-PATH permit 10
match ip address prefix-list TARGET
set as-path prepend 65010 65010
exit
route-map LONGER-PATH permit 20
exitrouter bgp 65010
address-family ipv4 unicast
neighbor 192.0.2.2 route-map LONGER-PATH out
exit-address-familyR1# clear ip bgp 192.0.2.2 soft outIllustrative outbound UPDATE
R1 → R2
NLRI: 198.51.100.0/24
AS_PATH: 65010 65010 65010
NEXT_HOP: 192.0.2.1Check the remote choice
R2# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
* 198.51.100.0/24 192.0.2.1 0 0 65010 65010 65010 i
*> 192.0.2.6 0 0 65010 iR2# show ip route 198.51.100.0
Routing entry for 198.51.100.0/24
Known via "bgp 65020", distance 20, metric 0
* 192.0.2.6, via GigabitEthernet2With equal weight and effective local preference, the shorter path from R3 wins. This is R2’s choice for traffic entering the originating AS; it does not directly change R1’s own outbound route selection.
Know the limits
Prepending is an influence, not a guaranteed traffic-engineering contract. A remote AS can prefer a higher local preference or weight before considering AS-path length. Its filters may reject an excessively long path. Use your authorized local AS for this experiment; do not insert arbitrary other AS numbers. An AS path describes advertised AS reachability, not every router or packet hop.
Restore the baseline
On R1, detach the policy and refresh the advertisement.
router bgp 65010
address-family ipv4 unicast
no neighbor 192.0.2.2 route-map LONGER-PATH out
exit-address-familyR1# clear ip bgp 192.0.2.2 soft outR2# show ip bgp 198.51.100.0/24
Network Next Hop Metric LocPrf Weight Path
*> 198.51.100.0/24 192.0.2.1 0 0 65010 i
* 192.0.2.6 0 0 65010 iKey Takeaways
- A shorter ordinary AS sequence is preferred only after earlier comparisons tie.
- Prepending adds extra copies of the advertising AS to a chosen exported path.
- An ordinary external advertisement adds its own local-AS copy as well.
- Prepending influences the receiving AS’s entry choice, not a guaranteed traffic ratio.
- Remote local policy and filtering can outweigh or reject a prepended advertisement.
Protocol and command references
Best-path comparison rules · BGP path attributes · Router-symbol attribution.