Adjusting Local Preference Values

Problem

You want to change the Local Preference values to control which routes you use.

Solution

There are two ways to adjust Local Preference values on a router. The first method changes the Local Preference values for every route distributed into iBGP from this router:

Router1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router1(config)#router bgp 65500
Router1(config-router)#bgp default local-preference 200 
Router1(config-router)#exit
Router1(config)#end
Router1#

The second method uses route maps to give finer granularity control over which routes get what Local Preference values:

Router1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router1(config)#ip prefix-list LOW_LP_PREFIXES seq 10 permit 172.22.0.0/16
Router1(config)#route-map LOCALPREF permit 10
Router1(config-route-map)#match ip address prefix-list LOW_LP_PREFIXES
Router1(config-route-map)#set local-preference 50
Router1(config-route-map)#exit 
Router1(config)#route-map LOCALPREF permit 20
Router1(config-route-map)#exit
Router1(config)#router bgp 65500
Router1(config-router)#neighbor 192.168.1.5 remote-as 65510
Router1(config-router)#neighbor 192.168.1.5 route-map LOCALPREF in
Router1(config-router)#exit
Router1(config)#end
Router1#

 

Discussion

When BGP routers within an AS exchange information about a particular route using iBGP, they include the Local Preference value. All of the routers in the AS are then able to use this value to decide how to weight this route versus other BGP routes to the same destination. BGP consults the Local Preference value early in the route selection process, before even the AS Path attribute. So this provides an extremely useful and flexible way of forcing particular routes to use particular paths. Routers do not include Local Preference information when exchanging routes through eBGP connections.

A common example would be if you had two connections to an external network and you wanted to ensure that one was the primary path and the other was a backup. Suppose further that one of the routers in the AS handles the primary path and a second router handles the secondary path. The first example shows how to globally increase the Local Preference values of all routes received by one of these routers:

Router1(config)#router bgp 65500
Router1(config-router)#bgp default local-preference 200 

Now all of the external routes that this router handles will have a Local Preference value of 200. If you can reach a particular prefix through more than one path, the other routers in this AS will prefer to use the one with the highest Local Preference value. The default Local Preference is 100.

To see how this works in practice, we will once again use the network shown in Figure 9-2. The following output shows two paths to the network 10.0.0.0/8. This router learned the first route through iBGP from another router. You can see from the LocPrf column that this route has the default Local Preference value of 100:

Router2#show ip bgp
BGP table version is 4, local router ID is 172.18.5.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

 Network Next Hop Metric LocPrf Weight Path
* i10.0.0.0 172.18.5.2 100 0 65510 65531 i
*> 192.168.2.5 0 65520 65531 i
Router2# 

This router learned the second route through eBGP, so it doesn't have a Local Preference value. The router treats any missing Local Preference values as if they had the default value of 100. Note that although BGP has a route selection rule that prefers eBGP routes to iBGP routes, this rule is consulted after the Local Preference is, but for now the Local Preference values are equal. So, all other things being equal, this router prefers to use the more direct route that it learned itself, which is indicated by the ">" character at the beginning of the line.

Now we will change the default Local Preference value on the other router to 200, using the bgp default local-preference command as shown above:

Router2#show ip bgp
BGP table version is 4, local router ID is 172.18.5.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

 Network Next Hop Metric LocPrf Weight Path
*>i10.0.0.0 172.18.5.2 200 0 65510 65531 i
* 192.168.2.5 0 65520 65531 i
Router2#

As you can see, the Local Preference value has changed to 200 for the iBGP route. So this router now prefers the iBGP route. You can see more detail by specifying the prefix with this command:

Router2#show ip bgp 10.0.0.0/8
BGP routing table entry for 10.0.0.0/8, version 4
Paths: (2 available, best #1, table Default-IP-Routing-Table)
 Advertised to non peer-group peers:
 192.168.2.5 
 65510 65531
 172.18.5.2 from 172.18.5.2 (172.18.5.2)
 Origin IGP, localpref 200, valid, internal, best
 65520 65531
 192.168.2.5 from 192.168.2.5 (172.21.1.1)
 Origin IGP, localpref 100, valid, external
Router2#

This clearly shows that the router interprets the missing Local Preference value as 100 on this router. If we now change the default value on this router to 75, you can see that it will use this new value instead when the value is missing:

Router2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router2(config)#router bgp 65500
Router2(config-router)#bgp default local-preference 75
Router2(config-router)#end
Router2#clear ip bgp *

Router2#show ip bgp 10.0.0.0/8
BGP routing table entry for 10.0.0.0/8, version 2
Paths: (2 available, best #2, table Default-IP-Routing-Table)
 Advertised to non peer-group peers:
 192.168.2.5 
 65520 65531
 192.168.2.5 from 192.168.2.5 (172.21.1.1)
 Origin IGP, localpref 75, valid, external
 65510 65531
 172.18.5.2 from 172.18.5.2 (172.18.5.2)
 Origin IGP, localpref 200, valid, internal, best
Router2#

Notice that we had to clear the BGP peers and wait until they reconnected for this change to take effect. Also notice that, by chance, the router displays the routes in the opposite order. There is no particular significance to this ordering. The route that entered the AS via eBGP on this router (Router2) now has a Local Preference value of 75, while the route that entered via Router1 has a Local Preference of 200, which we configured earlier in this recipe.

You can also use route maps to define different Local Preference values for different individual routes. This gives you a finer granularity, even allowing you to manually balance the load between these links by forcing some routes through one path and the rest through the other path.

The second example shows how to use a route map to adjust Local Preference values:

Router1(config)#ip prefix-list LOW_LP_PREFIXES seq 10 permit 172.22.0.0/16
Router1(config)#route-map LOCALPREF permit 10
Router1(config-route-map)#match ip address prefix-list LOW_LP_PREFIXES
Router1(config-route-map)#set local-preference 50
Router1(config-route-map)#exit
Router1(config)#route-map LOCALPREF permit 20
Router1(config-route-map)#exit

Here we have defined a prefix list that just matches the prefix 172.22.0.0/16. Whenever the route map sees a route that matches this prefix list, it sets the Local Preference value for this route to 50.

We have included an empty clause at the end of the route map, which simply passes all other routes unchanged. Every route map ends with an implicit deny all. So if we didn't include this, the router would simply drop any prefixes that didn't match the first clause.

Then we invoke this rule by using the standard route-map option to the neighbor command:

Router1(config)#router bgp 65500
Router1(config-router)#neighbor 192.168.1.5 remote-as 65510
Router1(config-router)#neighbor 192.168.1.5 route-map LOCALPREF in

Notice that we are applying this route map to all incoming routes received from this specific eBGP peer. Now you can see that this particular route has a local preference value of 50:

Router1#show ip bgp 172.22.0.0/16
BGP routing table entry for 172.22.0.0/16, version 5
Paths: (2 available, best #2, table Default-IP-Routing-Table)
Flag: 0x208
 Advertised to non peer-group peers:
 192.168.1.5 
 65510 65531
 192.168.1.5 from 192.168.1.5 (172.25.26.55)
 Origin IGP, localpref 50, valid, external
 65520 65531
 172.18.5.3 from 172.18.5.3 (172.18.5.3)
 Origin IGP, localpref 75, valid, internal, best
Router1#

Note also that the other iBGP router is still using the Local Preference value of 75 that we configured a moment ago.

Because this method used a route map, you can easily construct rules that would change the Local Preference values based on a large variety of different parameters. For example, you could match based on the AS Path, which is a technique that we will discuss in more detail in Recipe 9.10. You could do this to give a higher or lower Local Preference value, based on whether or not the route passes through a particular remote AS:

Router1(config)#ip as-path access-list 17 permit _65531_
Router1(config)#route-map LOCALPREF permit 25
Router1(config-route-map)#match as-path 17
Router1(config-route-map)#set local-preference 75
Router1(config-route-map)#exit 

 

See Also

Recipe 9.10

Router Configuration and File Management

Router Management

User Access and Privilege Levels

TACACS+

IP Routing

RIP

EIGRP

OSPF

BGP

Frame Relay

Handling Queuing and Congestion

Tunnels and VPNs

Dial Backup

NTP and Time

DLSw

Router Interfaces and Media

Simple Network Management Protocol

Logging

Access-Lists

DHCP

NAT

First Hop Redundancy Protocols

IP Multicast

IP Mobility

IPv6

MPLS

Security

Appendix 1. External Software Packages

Appendix 2. IP Precedence, TOS, and DSCP Classifications

Index



Cisco IOS Cookbook
Cisco IOS Cookbook (Cookbooks (OReilly))
ISBN: 0596527225
EAN: 2147483647
Year: 2004
Pages: 505

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net