PacketLab
BGP · Attributes and Path Selection

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.

Lab topologyIllustrative network
.1 / .2 · eBGP.5 / .6 · eBGPR1AS 65010R2AS 65020R3AS 65010
Solid lines: physical links. Link labels use the last octet of 192.0.2.x; every link is a separate /30. AS labels identify the protocol relationship. Loopback0 is 10.255.0.N/32 for router RN. Exact interfaces and subnets are listed below.
LinkFirst endpointSecond endpoint
R1–R2R1 GigabitEthernet1: 192.0.2.1/30R2 GigabitEthernet1: 192.0.2.2/30
R2–R3R2 GigabitEthernet2: 192.0.2.5/30R3 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
end

R2

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
end

R3

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
end
Outputs are illustrative, not recorded router results. Each lesson is a separate lab. Allow updates to converge after changes; the selected baseline path is an example when all earlier criteria tie.
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 i
*                     192.0.2.6            0             0 65010 i

Prepend 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
exit
router bgp 65010
 address-family ipv4 unicast
  neighbor 192.0.2.2 route-map LONGER-PATH out
 exit-address-family
R1# clear ip bgp 192.0.2.2 soft out
Illustrative outbound UPDATE
R1 → R2
NLRI: 198.51.100.0/24
AS_PATH: 65010 65010 65010
NEXT_HOP: 192.0.2.1

Check 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 i
R2# 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 GigabitEthernet2

With 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-family
R1# clear ip bgp 192.0.2.2 soft out
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 i
*                     192.0.2.6            0             0 65010 i

Key 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.

AS Path Prepending Quiz

Six questions · four options each · select one answer per question. Submit all answers to see your score and explanations.

1. R1 adds two copies of AS 65010 before normal eBGP export. How many copies appear here?
2. What does the outbound prepend aim to influence?
3. Which path is shorter?
4. Can remote LOCAL_PREF override the shorter AS path?
5. Which AS should this experiment prepend?
6. Does an AS sequence identify every physical router hop?
Protocol and command references

Best-path comparison rules · BGP path attributes · Router-symbol attribution.