BGP AS Prepend Inbound Configuration Example

Rashmi Bhardwaj | Blog,Config & Troubleshoot,Protocol,Routing & Switching

In BGP configuration especially where Multihoming scenarios are used, AS prepend is one of commonly used a BGP feature which is used for path manipulation to influence the direction of the incoming traffic to an AS.

As a general understanding, AS prepend is applied only in an outbound direction to affect the incoming traffic to an AS.

Related – What is VRF


However, in this post, we will configure the AS prepend feature to IN direction and see how we can still achieve the same path manipulation as we could have achieved when AS prepend applied in OUT direction.


In this topology, on R1 we are getting the route R4 ( from two routers R2 & R3. Without any traffic manipulation we see we are able to reach R4 from R1 via path R1 -> R3 -> R4.

R1#traceroute source

Type escape sequence to abort.

Tracing the route to

VRF info: (vrf in name/id, vrf out name/id)

1 92 msec 28 msec 16 msec

2 32 msec 64 msec 52 msec

We will now apply BGP AS prepend on R3 inbound to make path R1 -> R2 -> R4 the preferred path to reach router R4.


route-map in-prepend permit 10

set as-path prepend last-as 2

router bgp 100

bgp log-neighbor-changes

neighbor remote-as 100

neighbor update-source Loopback0

neighbor next-hop-self

neighbor remote-as 200

neighbor route-map in-prepend in

Now we have applied route-map in-prepend in inbound direction on R3 to make the AS-Path for via R3 the longer one.

Verifying now on R1 we see the path via R2 is best and via R3 is not preferred anymore as it has longer AS-path.

R1#sh ip bgp

BGP table version is 3, local router ID is

Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,

r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,

x best-external, a additional-path, c RIB-compressed,

Origin codes: i – IGP, e – EGP, ? – incomplete

RPKI validation codes: V valid, I invalid, N Not found

Network                Next Hop           Metric        LocPrf   Weight         Path

*>                 0                             32768             i

*  i                 0                100       0                      200 200 200 i

*>i                                  0                100       0                      200 i   <Best Path via R2>


Below is the Traceroute output to validate the expected output after configuration change –

R1#traceroute source

Type escape sequence to abort.

Tracing the route to

VRF info: (vrf in name/id, vrf out name/id)

1 76 msec 36 msec 32 msec

2 44 msec 88 msec 48 msec


Related – Interview Questions of BGP


Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart