How to configure BGP AS Path Prepending

The list with all BGP’s decisions for selecting the best path is quite long, this Cisco post has a good overview:

It also covers some of the things we normally don’t often talk about. For example, you can see that when everything for an external path that it will prefer the oldest route before using the router ID as a tie-breaker.

The router ID of Jim and John could be the same if the loopback is created before starting the BGP process.

Hi Team,

In the Cisco CCNP book, they say to use the inbound route map. I’m confused as to when we should use in our outbound? Can you please clarify?

Lovely site! Will continue to use.

Thanks

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.

Rene

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

outbound will affect inbound traffic

inbound will affect outbound traffic

Thanks

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.

Rene

http://i66.tinypic.com/33w3x29.jpgTopology

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: 8.8.8.8

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

For example:

R1(config-router)#network 192.168.1.0 mask 255.255.255.252

R2(config-router)#network 192.168.2.0 mask 255.255.255.252

One thing which I have noticed is if I do not advertise 192.168.1.0 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 192.168.1.0 mask 255.255.255.252

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.

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 8.8.8.8 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 8.8.8.8 through R1 but wants to use the IP address of R3 as the next hop which it doesn’t know. That’s why advertising 192.168.1.0/30 can make the difference. This also applies to R1 that learns 8.8.8.8 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 192.168.1.0/30 on R3 then all EBGP neighbors will learn this network. It will also allow R2 to learn the next hop for the 8.8.8.8 network.

Rene

Thanks a lot for the explanation Rene.

I would like you to clarify one more thing.

For the LAN segment: 192.168.100.0 : R1 is the active router to reach 8.8.8.8 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 8.8.8.8.

I have set a tracking object with IP SLA1 for type: echo to ping 8.8.8.8 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 8.8.8.8 from R2 (ibgp), that route starts being used and the reachability from R1 towards 8.8.8.8 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 8.8.8.8 route to R1.

Please explain. Thanks in advance. :slight_smile:

Shivam,
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 8.8.8.8 source-interface Serial0/0

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

--Andrew

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

thanks

Hi Abhishek,

That sounds about right, good job!

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

Rene

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!

Sravanthi,
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.

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-route-map)#exit
Jack(config)#router bgp 1
Jack(config-router)#neighbor 192.168.12.1 route-map PREPEND in

Mahmoud,
Your solution will also produce the same results–just make sure you do a “clear ip bgp 192.168.12.1 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!

Andrew, Many thanks for your support

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

Rene,

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

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,
Jon

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