How to configure BGP AS Path Prepending

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

Hi Laz,

I noticed Rene used:

R1(config)#route-map PREPEND permit 10
R1(config-route-map)#set as-path prepend 1 1 1 1 1
R1(config-route-map)#exit
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 route-map PREPEND out

Having this type of route-map, nothing will hit the implicit deny since we arenā€™t matching anything correct?

Hello Aung

AS Path Prepending is a feature that is shared only between ASs. It cannot be propogated within an AS using iBGP. There is no notion of AS paths within iBGP so it is information that is not relevant. Secondly, you can apply prepending inbound. What that will do is cause any shared routes from the particular neighbor to increase the number of prepended AS numbers. This is somewhat dangerous unless you are controlling both ASs involved in this route exchange and you can control what is being advertised to you to which you are prepending.

I hope this has been helpful!

Laz

1 Like

Hello sales2161

If there is no match statement, then route maps will automatically match everything by default. So everything that is processed by this route map will be matched and processed.

I hope this has been helpful!

Laz

1 Like

I have done AS PATH prepend to influence the inbound traffic on a dual homed setup, but even after prepend i still see 25% traffic using the same link. How do we completely make prepend work by not seeing any traffic coming from Internet on that link.

Does this needs any involvement from ISP?

Hello Sandeep

One of the things we have to always keep in mind when influencing inbound traffic using BGP is that we donā€™t have the last word on the subject. No matter what you do, your ISP has the capability of overriding any attempts by us to influence incoming traffic. For this reason, the best thing to do in such situations is to involve the ISP as you suggested. Talk with them, tell them what you require and find a solution that will be mutually beneficial.

I hope this has been helpful!

Laz

Thanks Lazaros, Just wondering if ISP wants to change BGP config what that would be as it will try to influence traffic coming from connected AS. Hope my question is valid. Please share your thoughts.

Hello Sandeep

Whatā€™s important is to let the ISP know what you need. There are always several ways of implementing your requirements. ISPs will usually accommodate your needs, or will provide you with alternatives to get the desired result.

Having said that, there are several ways that you can influence incoming traffic. These are leaking more specific routes, MED, AS-PATH Prepending and community/local pref agreement. All of these can be discussed as options with the ISP so you can have the result you require.

I hope this has been helpful!

Laz

1 Like

I think Fabian is correctā€¦

OUT is to influence INBOUND traffic and IN is to influence OUTBOUND trafficā€¦

Weight is for outbound traffic and we use IN and AS Path Prepend is for inbound traffic and we use OUT.

Please correct me if am wrong

Hi

What would happen I changed AS path and that conflicts with another AS path on the internet?

Hello Card

Remember that BGP routers share their information with their BGP neighbours. The out or in keywords donā€™t refer to the actual traffic being sent between the routers, but refers to the BGP advertisements. So by stating that R1 will add the route-map PREPEND on all outgoing advertisements, what it is saying is that when R1 tells R2 about how to reach the 1.1.1.0/24 network, which is an advertisement that is outgoing to the other neighbour, it will prepend the configured AS numbers.

I hope this has been helpful!

Laz