How to configure BGP AS Path Prepending

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

I understood this explanation immediately

Hi Daniel,

I might write a short tutorial on it with an example but it is a simple one. A BGP router will prefer routes that it installed into BGP itself over a route that another router installed in BGP.

Rene

The one below here in a the original post I did not understand:

Originate

Prefer the path that the local router originated. In the BGP table, you will see next hop 0.0.0.0. You can get a path in the BGP table through the BGP network command, aggregation, or redistribution.

This one threw me off with the language may be something specific to my thinking but I saw this and I didn’t get what you said so simply above. I know you said prefer the path of the local router but I did not put two and two together in the full context until I read it here in this forum post.

My suggest would be to take your answer in the forum post and change or add it to the original page: https://networklessons.com/cisco/ccnp-route/bgp-attributes-and-path-selection/ and less people may be confused.

I was trying to google originate and look it up in my advanced BGP group and could not find anything kept pulling up the Origin Attribute I also thought about posting something like he said until I read this forum and then I was like oh crap that is simple lol…

I was curious about this when I saw two routers with the same loopback alarms went off. Is this ok to do or would this cause issues and is just being used only for educational look at a specific learning topic?

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

Ok now on to my main question which is I don’t understand how this works because its doing something that to me seems non logical.

Capture

When I saw those commands to me that said that apply this on the out going 192.168.12.2 which is on R2. So seeing that I thought R1 would be the router however from the output it was just the opposite:

Capture

it did exactly the opposite that I thought it would have done. Instead of 1.1.1.0/24 and next hop being 192.168.12.1 being the primary it was as you can see above the 23.3… if you had wanted to effect 192.168.23.3 I would have sent out to that neighbor to effect. (that’s actually what it did but duh! I was thinking it would send something positive thus not understanding what the command actually did as I explain later in post)

==============================================================================

haha!!! I just figured it out as I took my time read through it again. At first I didn’t find anything but I knew it had to be something that was kind of obvious and had to be looking me in the face or there would have been a lot of others having issues with learning this but I saw a lot of “thanks for explaining this in straightforward manner” so I figured I missed something glaring at me and I just had to take my time and read more carefully and use a open view instead of focusing to heavily.

That’s when I found it and once again language bit me a bit.

The word Prepend was one hint that basically means add something to something. In this case it meant add more AS multiple times. First issue was I took it as a command I didn’t look at what the actual word where the actual word had meaning. I know what prepend means but I was looking at “set as-path prepend” meaning looking at it as something that was alien and not taking into account the definition of one of its part. That was first mistake. Next was not understanding a definition given because of a typo.

However, when I read this sentence it was missing an “S” see below:
Capture

So since the S was missing and me being me who takes things very literally and at a granular level I did not understand the sentence and over analyzed it and thinking I was not understanding some concept when in fact it was just a small typo that most people would have said oh its missing the “s”

When I started breaking things down word by word determined to find why I was not seeing the obvious I then saw it and had that head slap moment that I get so often.

Then it made since to me as we are saying add a bunch of path hops with same AS to the neighbor directly connected. This means that we increased the cost of R2 Neighbor 192.168.12.2 and its never going to be used since 192.168.23.2 is so much cheaper to use.

After that silly concept clicked in its like OH MY GOSH this is so simple and I now also get it. Please add an “S” sometime in the future but other than that others where right you really explain this clearly and I got it!

in addition, I was thinking this was directly about a BGP Attribute but its not its talking about a command that makes use of the BGP Attribute AS path length effect. I kept hopping over to the page where it talked about all of them looking for the Path Attribute set as-path prepend but of course it was not there as its not an Attribute but indeed a command. I was thinking each of the lesson pages in order was an Attribute so was a bit confused on that at first.

I agree, just added this sentence to the post :slight_smile:

Sometimes you can advertise the same IP address on multiple routers. I like to do it sometimes in labs as it saves a device…like in this BGP example.

With anycast RP, we also do it. Take a look at this example:

I just fixed this “add your own A number” error, it now says AS :wink: Thanks!

With commands like this, you have to see it from the router’s perspective where we configure it. On R1, we add something outbound to neighbor 192.168.12.2 so that means we send something to R2.

When you apply it inbound, it means we do something with the updates we receive from our neighbor.

In AS path prepending topic, in the config, AS Path prepend is configured in R1 but in router’s config. it is there in R3 router’s config. Is there any reason for this?

Hello Venkat

Thanks for catching that. You are right, the configs are incorrect. I will let @ReneMolenaar know to amend that.

Laz

Just fixed this, thanks for letting us know!

Dear NetworkLessones ,

i noticed that AS Path Prepending is used in EBGP between two AS and configured as outbound .
is it possible to use in between IBGP as inbound ? is there any problem ?

Regards,
Aung