How to configure BGP AS Path Prepending

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

1 Like

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

Just a question about the default behaviour on this example; you say R2 prefers 192.168.12.1 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?

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 192.168.12.1. So you are correct, it does prefer 192.168.12.1 but not because of the router ID but because of the lowest neighbour IP address. I’ll inform @ReneMolenaar about the correction.

Thanks!

Laz

Hello Reene,

This is Mohammed Farooq , I have doubt about the AS path lab that is covered .
I did the same lab with routers and the same config . I could see the traffic is preferred over the path between R2---- R3 but I could not see the next other path in show ip bgp on R2…

r2#sh ip bgp
BGP table version is 5, local router ID is 192.168.23.2
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
 *>  1.1.1.0/24       192.168.23.3             0             0 1 i


2#sh ip bgp su 
BGP router identifier 192.168.23.2, local AS number 2
BGP table version is 5, main routing table version 5
1 network entries using 140 bytes of memory
1 path entries using 80 bytes of memory
1/1 BGP path/bestpath attribute entries using 144 bytes of memory
1 BGP AS-PATH entries using 24 bytes of memory
0 BGP route-map cache entries using 0 bytes of memory
0 BGP filter-list cache entries using 0 bytes of memory
BGP using 388 total bytes of memory
BGP activity 2/1 prefixes, 3/2 paths, scan interval 60 secs

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
192.168.12.1    4            1      66      64        5    0    0 00:49:16        0
192.168.23.3    4            1       5       7        5    0    0 00:00:51        1
r2#

For troubleshooting purpose , I have shutdown the link between R2 to R3 … and found there are no routes to reach 1.1.1.0/24 to R1.

Hello mohammed

Since both 192.168.12.1 and 192.168.23.3 show up in R2 as neighbouring routers, and only R3’s route to 1.1.1.0 shows up, this means that for some reason R1 is not advertising its network to R2. Check your network statements on R1 as well as your AS numbers and IP address assignements.

I hope this has been helpful!

Laz

image

Initially it has taken path to 192.168.23.2 as it is the highest router.
But above it shows 192.168.12.1
I have configured same script

Hello Pavan

If you have configured the same configuration as that found in the lesson, your results should be identical to those described. Can you take a closer look at your configs and make sure that they are the same? Also, make sure to add the route-map to your BGP neighbour configuration. Since you are sending this to the remote neighbour, make sure that you use the out keyword at the end. Also BGP can take some time to reconverge, so check out the results after several seconds or even minutes.

I hope this has been helpful!

Laz