How to configure BGP AS Path Prepending

(Rene Molenaar) #17

Hi Fabian,

It depends which BGP attribute you are trying to influence. For AS path prepending, you normally use it to advertise the longer AS path to a remote neighbor. Other attributes like local preference are done on inbound.


(FABIAN M) #18

Thanks Rene. Regarding inbound and outbound, can we say the following?

outbound will affect inbound traffic

inbound will affect outbound traffic


(Rene Molenaar) #19

Hi Fabian,

It’s the other way around :slight_smile:

For example, when you use AS path prepending we configure it outbound. This means that the router on the side will receive the longer AS path…we are influencing them.

When we use a route-map to change the local preference, we do this inbound and it will influence our local AS.


(Shivam K) #20

Hello Rene,

This is the setup I am using to configure BGP multihoming.

AS 100 has two exit points to reach R5 which is hosting a subnet:

My Question is what difference does it make if I advertise directly connected subnets in BGP.

For example:

R1(config-router)#network mask

R2(config-router)#network mask

One thing which I have noticed is if I do not advertise subnet on R1, R2 did not know about it at all so advertising it on R1 did make sense.

Also, what difference will it make if I advertise the same subnet on R3 as well:

R3(config-router)#network mask

Please explain I’ve seen some interesting changes on R5 BGP table by playing with above configurations. Requesting you to please put some light here.

Many Thanks.

(Rene Molenaar) #21

Hi Shivam,

The main reason to advertise networks in BGP is so that you can reach them from remote networks.

In your example, the only network you want to advertise is since that’s what you are trying to reach. External BGP will change the next hop when you are advertising something so R1 and R2 will have no issues reaching this network through their external BGP neighbors.

Internal BGP is another story…it doesn’t change the next hop. R2 can learn through R1 but wants to use the IP address of R3 as the next hop which it doesn’t know. That’s why advertising can make the difference. This also applies to R1 that learns through R2.

Instead of advertising these networks you can also use next hop self for your IBGP neighbors:

BGP Next Hop Self

If you advertise on R3 then all EBGP neighbors will learn this network. It will also allow R2 to learn the next hop for the network.


(Shivam K) #22

Thanks a lot for the explanation Rene.

I would like you to clarify one more thing.

For the LAN segment: : R1 is the active router to reach and R2 is the standby as the priority for R1 is 150.

I am not using interface for tracking as i want the failover to happen on the basis of reachability of

I have set a tracking object with IP SLA1 for type: echo to ping and mapped it with Standby 1 on R1 to decrement priority by 90 if the ping fails.

To verify this, I did a “Shut” on the interface of R1 connecting to R3, what happened is as follows :

R1 was learning one more route towards from R2 (ibgp), that route starts being used and the reachability from R1 towards again gets restored, hence preemption takes place which makes R1 again an Active router.

Am i doing something wrong here, or should i setup a route map from R2 towards R1 to deny advertising route to R1.

Please explain. Thanks in advance. :slight_smile:

(Andrew P) #23

The easiest fix for this is to include the option of “source-interface” when creating your ip sla object.

For example:

ip sla 1
 icmp-echo source-interface Serial0/0

This way, even though R1 learns about via R2, it can no longer use the Serial0/0 interface to get there, so the track object will fail.


(Abhishek D) #24

Hi Rene, many thanks .
I have read the details about all attributes and does below stands correct if i need to review them quickly

weight : local to router - to tell its IBGP neighbors that i have better outer to a network.
local pref : inside a bgp AS (to let other IBGP neighbor know how to reach a outside network)
AS Path prepending : between 2 AS - to advertise to your neighbors how they should enter your AS
BGP Origin code : network command v/s redis.
BGP Metric (MED) : between 2 AS - to advertise to your neighbors how they should enter your AS


(Rene Molenaar) #25

Hi Abhishek,

That sounds about right, good job!

Cisco also has a very detailed example if you want to know all attributes.


(Sravanthi N) #26

Hi Rene,

What attributes will help to influence exit path to different AS? Example : A router in AS1 is peering with B and C in AS2 and AS3. B and C are transient routers that connect to internet. How does router A decide which transient router to go through?

Thank you!

(Andrew P) #27

The short answer is almost any BGP attribute can influence which AS is going to be used–that’s the purpose of the BGP Bestpath Selection Algorithm.

Here are a few examples:
Weight: Since you have a single router connected to multiple other ASNs, you can use weight on your router to determine which ASN is used for what route.

Local Preference: In your case (single router), this has the same effect as weight

Short AS Path: Perhaps for route X, there is a shorter as path from AS2 instead of AS3. In this case, your router would choose to route through AS2 (unless weight or local preference is used).

Now, if you are asking which attributes are under your control to influence outbound path selection, by far the most common one would be Local Preference. Weight isn’t popular to use because it is significant only to the local router, and it is Cisco proprietary.

(Mahmoud H) #28

Hi Rene,
Many thanks for your explain. i have a question regarding route-map in or out
if we configure the following on router jack, we will get the same result or not?

Jack(config)#route-map PREPEND permit 10
Jack(config-route-map)#set as-path prepend 1 1 1 1 1
Jack(config)#router bgp 1
Jack(config-router)#neighbor route-map PREPEND in
(Andrew P) #29

Your solution will also produce the same results–just make sure you do a “clear ip bgp in” after you apply the route-map to the neighbor. Sometimes with a situation like this you have to be careful about BGP order of operations–for example, does BGP run its best path selection algorithm before or after the route-map makes its changes? So in this case, I tested it, and your solution works great!

(Mahmoud H) #30

Andrew, Many thanks for your support

(Shantel - split this topic #31

19 posts were merged into an existing topic: How to configure BGP AS Path Prepending

(christopher w) #34


Just trying to get this straight in my head. so path prepending is basically like adding hop count because it is a distance vector technology and it is a way of manipulating the direction along with a route map . do I have this right

thank you for your great bgp lesson thus far. i’m at the bgp communities section

(jonrandall) #35

Hi @chriscowboyfann,

Apologies for jumping into the thread here but I think you are absolutely correct in your analysis; this is a great way to think about path pre-pending. Different vendors implement it in different ways but the idea is the same. As a rule of thumb, we always try to control the BGP path selection using the easiest to understand and troubleshoot criteria available to us. Path length is a great parameter to manipulate if done carefully.

When using AS path modification in production, you should be careful not to accidentally introduce backdoor routes so always test, check and re-check before and after implementation! :slight_smile:

Kind regards,

(christopher w) #36

Jon your input is always welcomed. OK great! that is what I thought. I will definitely keep that in mind. I truly appreciate your help.

Thank You Much

(Chris N) #37

Just a question about the default behaviour on this example; you say R2 prefers due to a lower router ID, however wouldn’t R1 and R3 have the same router ID due to advertising the same loopback? So actually the tiebreaker would be next lowest neighbour IP address?

(Lazaros Agapides) #38

Hello Chris

BGP will choose the router ID based first on if the router-id command is present. It is not in this case. Secondly, it will choose the highest IPv4 IP address of a loopback interface. You are correct, that both R1 and R3 have the same loopback address (seen in the configs), and thus would be advertising the same router-id. So the next step would be to determine the lowest neighbour IP address, which is indeed So you are correct, it does prefer but not because of the router ID but because of the lowest neighbour IP address. I’ll inform @ReneMolenaar about the correction.