Image of Cortney & Jeremy

Using BGP’s local preference to influence outbound routing

by Jeremy L. Gaddis on March 7, 2009 · 5 comments

in Networking

At the end of my last article, “Using AS path prepending to influence inbound routing“, I mentioned:

“Notice anything weird there? Yeah, traffic from R6 is first going to R7, then to R9 over that T1 connection, NOT the much faster 100 Mbit/s connection! How can we change that? The next article will continue on from here and we’ll change the configuration of our routers in AS 67 to address that.”

We’re going to continue where we left off and create another route-map, this time to manipulate the local preference value assigned to routes received from one of our BGP neighbors. We want to do this so that the fastest connection out of our AS is the preferred one for outgoing traffic.

Here’s the topology we’re dealing with:

We want all outgoing traffic to exit our AS over the 100 Mbit/s connection between R7 and R8, assuming it is available.

The default local-preference, or “local pref”, value assigned to routes is 100. Let’s look at the BGP table on R7 and examine what paths we have received to get to (R9):

R7# sh ip bgp | be Network
   Network          Next Hop            Metric LocPrf Weight Path
*>i172.16.66.0/24              0    100      0 i
*>                  0         32768 i
*>              0             0 88 i
*                                     0 99 88 i
* i                     0    100      0 88 i
*                            0 88 99 i
*>                      0             0 99

We can see that we have received a total of two routes to, one via R8 in AS 88 and the other from R9 in AS 99. Because the path directly to AS 99 is shorter than the path that traverses AS 88, it has been selected as the best path. Traffic destined to AS 99 will exit our AS over the (slow, in comparison) T-1 connection between R7 and R9. We want to change that and ensure that all traffic exits over our 100 Mbit/s connection into AS 88.

Easy as pie. Just like manipulating the AS Path, we’re going to create a simple route-map that takes care of this for us. The route map sets the local preference of received routes to 500 (remember, the default is 100) — higher local preference values win out. We’ll apply this route map to the BGP session between R7 and R8 and be done with it:

R7(config)# route-map LOCALPREF permit 10
R7(config-route-map)# set local-preference 500
R7(config-route-map)# router bgp 67
R7(config-router)# neighbor route-map LOCALPREF in

Now we need to clear the inbound BGP session with R8. Fortunately, we used the “neighbor soft-reconfiguration inbound” command so we can do a route refresh without having to tear down the BGP session and bring it back up:

R7# clear ip bgp soft in

Let’s look at R7’s BGP table now:

R7# sh ip bgp | be Network
   Network          Next Hop            Metric LocPrf Weight Path
*>i172.16.66.0/24              0    100      0 i
*>                  0         32768 i
*>              0    500      0 88 i
*                                     0 99 88 i
*>                   500      0 88 99 i
*                       0             0 99 i

Notice that the routes we have received from now have a local preference value of 500 assigned to them. The preferred route to is via (R8 in AS 88), even though the AS Path is longer! How cool is that? If we run the same traceroute from R6 to R9 again, we’ll see that the traffic does, indeed, take this new, preferred path:

R6# traceroute source

Type escape sequence to abort.
Tracing the route to

  1 8 msec 4 msec 4 msec
  2 4 msec 12 msec 8 msec
  3 4 msec *  28 msec


{ 5 comments… read them below or add one }

Leave a Comment

Previous post:

Next post: