How to configure BGP AS Path Prepending

Hello Card

BGP routers on the Internet are well protected from any AS paths that you can throw at them. They are configured to accept information only from authorized sources. If this was not the case, routing on the Internet would be unreliable. You can try to influence routing to your IP addresses using BGP, but ultimately, the administrator of each router on the Internet can override your attempts.

I hope this has been helpful!


Quite useful discussion, makes things clearly understood in this case. One question though I have is the case when router advertises the routes not originated locally by ‘network’ command but received from

  1. BGP neighbor - can we still manipulate advertisement of the received routes by prepends? On received router?
  2. IGP neighbor (say OSPF) and then redistributing them into BGP - how we then use prepend to advertise these routes further to BGP neighbors? Like in the case of redundant paths in two locations advertised over OSPF and redistributed into BGP so one location is preferred over the other.
  3. Or is it better to manipulate preferences in OSPF itself - can the metric/preference be then reflected in BGP from redistribution or not, in which case we would need to manipulate the preference still in the BGP itself?

Hello Vadim

The route maps that are used to implement AS Path Prepending do not discern between the source of the information being sent. If a path is being advertised by BGP to its neighbor, regardless of how it was initially learned, the prepending will take place. You can apply the route maps either outgoing or incoming. It is important to note here that outgoing and incoming do not have to do with the direction of user traffic, but the direction of the BGP updates being exchanged. So, if you apply the route map outgoing, then all routes that are shared or sent to that particular BGP router (outgoing on that particular interface) will have the prepending applied before being sent. If it is configured on an incoming basis, then any routes that are received from that neighbor (incoming on that particular interface) will have the prepending applied before being placed in the BGP table. This is the case whether you are advertising routes learned via BGP or routes that are redistributed from an IGP.

It all depends on what you want to achieve. Best practice dictates that you should make adjustments in cost within the routing protocol that you want to know about those adjustments.
So if you want OSPF to “know” of these changes in routing preferences, then you should configure it in OSPF only. If you want BGP to “know” then you should adjust (using prepending or another method) within BGP. Keep the routing adjustments you want to apply as localized to the specific routing protocol as possible. Adjust redistribution costs only as needed. This makes configurations simpler and maintains more straightforward operation.

I hope this has been helpful!


Great, thanks. As often the case after the question is explained it looks kind of obvious. :slight_smile:

1 Like


I just want to ask how can you guys remember which attributes apply to inbound and which apply to outbound. Because I always mess up which is which. So what I’m trying to ask is whether there’s another way to remember other than just cram up that weight and local pref is for outbound traffic while AS prepend and MED is for inbound traffic.

The other question I have is since some of the attributes are for inbound, some are for outbound. If we are trying to figure out a best bath for the inbound traffic, should we just ignore the outbound related attributes?

I hope my questions make sense.

Thank you for your help,

Hello Helen

All attributes must be examined when determining which route is the best to be taken. The attributes are not separated into those that apply to inbound and those that apply to outbound routes. All attributes apply to determine the best route from the local router to a particular destination. In this sense, all attributes affect outbound traffic only.

What you can do however is use some particular attributes to influence incoming traffic. This is often useful when configuring the edge of your network, especially if you have multiple ISPs to which you are connecting, and you have public IP addresses on your network that you want to advertise with BGP to the internet.

Influencing incoming traffic means that you can configure an attribute on your local router, that will be shared to neighboring routers, like those in your ISP, such that the choice of their best routes to your internal prefixes can be “steered” via the link that you prefer. Remember, you are trying to influence certain attributes on the remote routers, such that they choose the preferred outgoing route to get to your prefixes. So it’s still outgoing traffic that is being affected but from the point of view of the remote router.

Remember however, that you do not have ultimate control over how your ISP’s routers will route traffic. They can always override your influence. That’s why it is a good idea to talk with your ISP about your requirements so that you can come to a mutual agreement on how to route traffic.

Now the attributes that can be used to influence incoming traffic are:

In addition to this, you can also leak more specific routes to your ISP, since BGP prefers more specific routes over less specific routes. But this may be viewed as a “hostile” act by your ISP, so make sure you speak with them first!

Beyond just remembering them, I don’t know of another way in which to keep them in mind. It might be helpful to more fully understand how they work, then you may be able to more readily remember them.

I hope this has been helpful!


That’s very helpful. Thank you Laz.

1 Like

Hello Muahmmed,

The above attached lab is working with same configuration template which is showing both routes in my R2 bgp table but choose best as (less AS to reach the network per your information even i purposefully shut my R2 interface towards R3 which is currently working as best path replace with seeing any issues with BGP convergence process when the primary path (least AS preferred) went down.

1 Like

Hi Gentlemen,

Is it possible to control incoming path based on a source prefix only , meaning I only want to allow traffic to come into my AS through ISP1 while all others would go through either ISP. Is that possible? AS path prepending seems to only allow me to advertise my prepended AS’s to my neighbor of my choice. Thanks,


Hello Barry

A fundamental principle when dealing with BGP on your network edge is that when you advertise your public IP prefixes to the internet using BGP, you can influence incoming traffic to take a particular route but you don’t have ultimate control.

What this means is that you can try to get the BGP neighbors of your edge routers, specifically, the ISP routers, to prefer one route over another to get to your prefixes. But any such attempt can be overridden by your ISPs. The best course of action is to talk with your ISPs, let them know what you want to do, and coordinate with them on how to achieve it.

Now the attributes that can be used to influence incoming traffic are:

In addition to this, you can also leak more specific routes to one of your ISPs, since BGP prefers more specific routes over less specific routes. But this may be viewed as a “hostile” act by your ISP, so make sure you speak with them first!

I hope this has been helpful!


I am a bit confused about usage of inbound or outbound. When we use the LocalPreference attribute we used “in” while mapping the route-map to the neighbor. But when we use AS Path attribute we use “out”. I thought that we influence the ISP router with both attributes. When we use “in” is that influencing outgoing traffic, and when we use “out”, does it mean that we influence “incoming” traffic. Could you please explain a bit more?

Hello Ike

When using route maps to adjust BGP attributes in this way, it is important to understand that the direction of in or out that is configured refers not to actual traffic, but to the direction of the BGP updates.

When you configure a change in local preference in an incoming direction, what the router is saying is: “Any BGP advertisements that enter this interface must have their local preference changed”

You can also do this in an outbound direction which would say: “Any BGP advertisements I send out this interface, I will change the local preference before I send them”

When it comes to AS path, the same thing applies. In an outbound direction, the router is saying “I will prepend these AS’es in the path of the prefixes in outgoing BGP advertisements before I send them to my neighbor.”

Whether you use in or out will depend upon what you actually want to achieve.

I hope this has been helpful!


Thank you Lazaros, this is very helpful.

1 Like

Hi guys,

I configure AS prepend in R2 and R3 to advertise the prefix &
From R7, the sh ip bgp output shows the prefixes are prepended. However from R6, the sh ip bgp output shows both prefixes have equal AS-Path.

Is this normal behavior? Somehow the AS-Path prepend info from R7 is not passed forward to the other routers.

Adding on, if R2 or R3 is down, traffic is able to forward successfully. I believe my configurations are valid but I want to know why R6 is not getting the prepend info

Hello Saifundin

That’s strange, because AS prepending should be propogated to other AS’s downstream. I suggest you take a look at the following in order to continue your troubleshooting:

  1. Examine the AS paths associated with each of the prefixes and in R7, R5, and R4 as well and see from which router on the AS’s are removed.
  2. Check to ensure that the two prefixes are not being summarized in one of the downstream routers
  3. Ensure that there are no other route maps or other configurations in R7 or other routers that will affect the prepended AS’s

I believe that if you see where the prepended AS’s are removed (that is, at which router, R7, R4, R5) it will give you a better clue about where the problem lies. Let us know how you get on with your troubleshooting.

I hope this has been helpful!


Hi Rene,

In this lesson, we’re in charge of both As’s, in the real world we’re only in charge of our own AS, how to include inbound traffic like AS path prepending if I’m only in charge of one AS

Hello Walter

Yes you are correct, in the real world you only have control over your own network. As such, you have ultimate control over your outbound traffic, but you do not have ultimate control over your inbound traffic. However, as you can see from this example, it is possible to try to influence incoming traffic.

If you are admin of AS1, then you can cause the BGP routing of AS2 to prefer one path over another. Of course, the admins of AS2 are able to override such attempts by making the appropriate adjustments on their end. Remember, they have ultimate control over their outbound traffic too.

If you come up to such a scenario at your interface with another network, such as your ISP, it is always best to discuss what you would like to do before you implement it. Any attempt to influence their traffic may be considered hostile or inappropriate. Always discuss your intentions before applying any such BGP implementations.

More info about this can be found at this post:

I hope this has been helpful!


thanks Laz, you’re a great teacher:)

1 Like

Thanks so much, Walter! I appreciate your kind words! I do my best :blush: .


I love this website is so useful, I have interview for Verizon this Thursday I hope I will pass:) ,
This website will help so much for everyday work there !