Two Equal Paths, one iBGP one eBGP, iBGP wins

We have three routers:


Provider AS1 is advertising a prefix eg: to R1 & R2. Due to path selection, R2 is preferring the route to the prefix via R1due to the iBGP having a higher preference.

To get around this a route map is being used on R1 & R2 to prefer it’s own eBGP routes:

 route-map ImportRoutesSIP permit 10
 set local-preference 250
 set weight 200

Traffic flows from R3 to R2 as it has selected the route as its preferred route as it has two iBGP links to either router. However, all routers are in different datacenters, R1 and R3 are both in the same City, R1 & R3 are 208 miles away from R2.

What is the best way to get R3 to prefer prefixes of the same length from R1 over R2? Using WEIGHT would prefer all routes no matter what their AS length is, which is not preferred. So is there a cost we can apply as we do in OSPF?

I have been testing and it appears all I need to do is set a ‘metric’ on the sessions between R1 <—> R3 and R2 <—> R3.

This was done by using the following:

 route-map InternalExportIntercity permit 10
 description Export Routes And Apply Metric
 set metric 20

R3 now selects the path closest to it with the same AS path over the router in the different city.

Hello Ross

It’s great to hear that you’ve got it working, and that’s always the goal! To address your questions however, I’d like to ask for a little more information. For clarification, I’ve created the following topology:

Can you explain this for me? It seems that if both R1 and R2 are receiving the same prefix via eBGP from AS1, then R2 shouldn’t be preferring the prefix via R1, but via its own eBGP peering. Is there some modification made to the default attributes that is causing this behaviour?

I’m not sure what you mean here when you refer to length. Do you mean prefix length ( you mention prefixes of the same length) or AS PATH Length? I assume you mean the latter. You can manipulate the AS PATH length by using AS path prepending. You can find out more about it here:

It turns out that there are several ways in which you can affect outgoing traffic. You can use AS PATH prepending, as mentioned before, you can adjust the MED attribute, which is the metric as you described it above, or you could also use the local preference feature which will prefer a particular “exit point” out of your AS over another, which is essentially what you are doing in your topology. You can find out about these other BGP attribute adjusting features at the following lessons:

I hope this has been helpful!


The issue wasn’t as obvious as I first thought, I was looking at the port usage graphs that spiked when I set the same local preference on the for each peer on R1 and R2. The change meant that R3 started to use the R2 route and therefore traffic from one city was incorrectly sent to another city, e.g. R3 -> R2. From R3’s point of view, the routes were the same as both routes were learned over iBGP and both had the same local preference.

The solution for this was to add a higher ‘metric’ value for routes that were intercity. Therefore this metric was added for the links R1 <-> R2 and R2 <-> R3. Each router now prefers routes to other networks within the same geographic location.

Hello Ross

Thanks so much for sharing that, and glad to hear that all is well with your topology.