Hands-On Lab: Configuring BGP AS-Path Prepending

This hands-on lab configures AS-path prepending on one outbound BGP path to make it appear artificially longer to external peers, influencing an upstream AS's inbound path selection without that AS needing any configuration change of its own.

AS-Path PrependingInbound Traffic EngineeringMulti-Homed AS Path Manipulation

~4 min read · Updated Sep 26, 2026

Lab Objective

Configure a route-map that prepends extra AS numbers to a specific outbound route advertisement, verify the resulting AS-path length increase as seen by an external peer, and confirm that peer now prefers the shorter, non-prepended path via the alternate connection.

Lab Purpose

Local preference and weight, covered in the previous lab, only influence how routers within one's own AS choose among multiple outbound paths. Neither can influence how an external AS chooses among multiple paths back into the local AS. AS-path prepending solves this specific inbound traffic engineering problem by making one path look artificially less attractive from the outside.

Lab Topology

AS 65040 is multi-homed to the internet via
two connections:

R1 (AS 65040) ---- eBGP ---- ISP-A (AS 65100)
R2 (AS 65040) ---- eBGP ---- ISP-B (AS 65200)

Goal: make the ISP-B path the secondary/
backup path, with ISP-A preferred for
inbound traffic toward AS 65040's network
192.168.240.0/24

Task 1: Verify Both Paths Appear Equally Attractive Initially

Confirm ISP-A and ISP-B currently see the AS-path for 192.168.240.0/24 as the same length.

Task 2: Configure AS-Path Prepending on the R2-ISP-B Path

Configure a route-map on R2 that prepends AS 65040 three extra times to routes advertised toward ISP-B.

Task 3: Apply the Route-Map to the Outbound Advertisement

Apply the prepending route-map as an outbound policy toward ISP-B.

Task 4: Verify the Prepended AS-Path from ISP-B's Perspective

Confirm ISP-B now sees an artificially lengthened AS-path for this route.

Task 5: Verify ISP-B Now Prefers the Alternate Path (If One Exists on Their Side)

Confirm, from a router simulating a third-party AS receiving both paths, that the shorter (ISP-A) path is now preferred.

Solution and Verification

ThirdPartyAS# show ip bgp 192.168.240.0

   Network              Next Hop       Path
*> 192.168.240.0/24    [via ISP-A]     65100 65040 i
*  192.168.240.0/24    [via ISP-B]     65200 65040 i
-- Both paths currently show AS-path length
-- 2, appearing equally attractive by this
-- metric before prepending

R2(config)# route-map PREPEND-TO-ISPB permit 10
R2(config-route-map)# set as-path prepend 65040 65040 65040

-- Prepending R2's OWN AS number (65040)
-- three additional times, since AS-path
-- prepending always adds copies of the
-- advertising AS's own number, never a
-- fabricated or third-party AS

R2(config)# router bgp 65040
R2(config-router)# neighbor [ISP-B address] route-map PREPEND-TO-ISPB out

ISPB-Router# show ip bgp 192.168.240.0

   Network              Next Hop       Path
*> 192.168.240.0/24    [via R2]        65040 65040 65040 65040 i
-- ISP-B now sees an AS-path of length 4
-- instead of 1 (from their direct
-- perspective) -- three prepended copies
-- plus the original AS number

ThirdPartyAS# show ip bgp 192.168.240.0

   Network              Next Hop       Path
*> 192.168.240.0/24    [via ISP-A]     65100 65040 i
*  192.168.240.0/24    [via ISP-B]     65200 65040 65040 65040 65040 i
-- The ISP-A path (AS-path length 2) is now
-- clearly shorter than the ISP-B path
-- (AS-path length 5), so any third party
-- applying BGP's standard shortest-AS-path
-- preference rule will choose the ISP-A
-- path for traffic destined to
-- 192.168.240.0/24

Key Takeaway

AS-path prepending works precisely because it exploits BGP's own standard best-path rule preferring a shorter AS-path — rather than requesting ISP-B to change its own configuration, AS 65040 makes its own advertised route look objectively less attractive using a rule every BGP-speaking router in the world already applies by default, making this the standard technique for influencing inbound traffic engineering across an AS boundary an administrator does not control.

Written & researched by Dr. Shahin Siami

Related Articles

Hands-On Lab: Configuring EIGRP Stub Routing

This hands-on lab configures a branch router as an EIGRP stub, verifying it advertises only its own connected and summary routes while the hub router correctly avoids querying the stub during a topology change elsewhere in the network.

Continue

Hands-On Lab: Configuring EIGRP Named Mode

This hands-on lab reconfigures a classic EIGRP setup into EIGRP named mode, organizing address-family and interface-specific configuration into a more structured hierarchy, and verifies functional equivalence with the classic configuration style used throughout earlier EIGRP labs in this series.

Continue

Hands-On Lab: Configuring ERSPAN Across a Routed Network

This hands-on lab configures Encapsulated RSPAN (ERSPAN) to mirror traffic across a Layer 3-routed network rather than a single Layer 2 trunk, extending the RSPAN concept from the previous lab beyond the boundaries of a single VLAN or switched domain.

Continue

Hands-On Lab: Configuring RSPAN Across Switches

This hands-on lab configures Remote SPAN (RSPAN) using a dedicated RSPAN VLAN carried across a trunk, allowing traffic mirrored on one switch to be monitored by a capture device connected to an entirely different switch, extending the local SPAN concept covered in an earlier lab across the network.

Continue

Hands-On Lab: Configuring In-Service Software Upgrade (ISSU) on a Stack

This hands-on lab performs an In-Service Software Upgrade across a StackWise stack, upgrading each member's IOS image one at a time while the stack continues forwarding traffic throughout, verifying zero downtime compared to the disruptive reload approach used in earlier IOS upgrade labs.

Continue

Hands-On Lab: Configuring Cisco Catalyst StackWise Traditional Stacking

This hands-on lab configures traditional Catalyst stacking (StackWise) across three switches using stack cables, contrasting its single-tier, chassis-proximity requirement against the StackWise Virtual pair covered in the previous lab, which allows switches to be located much farther apart.

Continue