RoutingRoute Policy Config

set local-preference [value]

Sets the BGP local preference value for routes matching the route policy, influencing the best path selection within an AS.

Overview

The 'set local-preference' command in Cisco IOS-XR is used within a route policy to modify the BGP local preference attribute for routes that match certain conditions. Local preference is a well-known discretionary attribute that influences the BGP best path selection process within an autonomous system (AS). A higher local preference value is preferred over a lower one, with the default being 100. This command is essential for traffic engineering, allowing network administrators to control outbound traffic flows by preferring certain paths over others. For example, you can set a higher local preference on routes received from a primary upstream provider to ensure that traffic exits via that link, while keeping a backup link with lower preference. In Cisco IOS-XR, route policies are configured in route-policy configuration mode and must be applied to BGP neighbors or address-families using the 'neighbor route-policy' command. The command is platform-specific to IOS-XR and differs from Cisco IOS where 'set local-preference' is used in route-map configuration. Understanding how to use this command is crucial for BGP optimization and troubleshooting, as misconfiguration can lead to suboptimal routing or traffic blackholing.

Syntax·Route Policy Config
set local-preference <value>

When to Use This Command

  • Prefer routes learned from a specific peer over others within the same AS.
  • Influence outbound traffic from the AS by setting higher local preference on routes from a preferred upstream provider.
  • Implement traffic engineering by adjusting local preference based on community tags.
  • Ensure backup links are used only when primary links fail by setting lower local preference on backup paths.

Parameters

ParameterSyntaxDescription
value<value>The local preference value to set. It is an integer from 0 to 4294967295. Higher values are preferred. The default is 100. Common values range from 50 to 200 for traffic engineering.

Command Examples

Set local preference to 200 for routes from peer 10.0.0.1

route-policy SET-LP if source in (10.0.0.1) then set local-preference 200 endif end-policy
RP/0/RP0/CPU0:router(config-rpl)#show rpl route-policy SET-LP
route-policy SET-LP
  if source in (10.0.0.1) then
    set local-preference 200
  endif
end-policy

The route-policy is defined. The 'if source in (10.0.0.1)' condition matches routes from neighbor 10.0.0.1. When matched, local preference is set to 200. The 'show rpl route-policy' output displays the policy content.

Set local preference based on community

route-policy COMM-LP if community matches-any (100:10) then set local-preference 150 endif end-policy
RP/0/RP0/CPU0:router(config-rpl)#show rpl route-policy COMM-LP
route-policy COMM-LP
  if community matches-any (100:10) then
    set local-preference 150
  endif
end-policy

This policy matches routes with community 100:10 and sets local preference to 150. The output confirms the policy definition.

Understanding the Output

The 'show rpl route-policy' command displays the route policy configuration. The output shows the policy name and the sequence of conditions and actions. Key fields include the 'if' condition (e.g., source, community) and the 'set local-preference' action. A healthy output shows the intended policy logic; a problem might be missing conditions or incorrect values. For example, if local preference is not set as expected, verify the condition matches the intended routes. The output does not show the actual local preference value applied to routes; use 'show bgp' to see the effect.

Configuration Scenarios

Prefer routes from a specific upstream provider

An enterprise has two upstream ISPs: ISP-A (primary) and ISP-B (backup). The goal is to prefer routes learned from ISP-A.

Topology

Enterprise Router (AS 65000) --- ISP-A (AS 100) Enterprise Router (AS 65000) --- ISP-B (AS 200)

Steps

  1. 1.Create a route-policy that sets local-preference 200 for routes from ISP-A.
  2. 2.Apply the policy inbound on the BGP session to ISP-A.
  3. 3.Verify with 'show bgp' that routes from ISP-A have local preference 200.
Configuration
!
route-policy PREFER-ISP-A
  if source in (10.0.0.1) then
    set local-preference 200
  endif
end-policy
!
router bgp 65000
  neighbor 10.0.0.1
    remote-as 100
    address-family ipv4 unicast
      route-policy PREFER-ISP-A in
    !
  !
!

Verify: show bgp ipv4 unicast | include 10.0.0.1 show bgp ipv4 unicast 0.0.0.0/0

Watch out: Ensure the neighbor address in the 'source' condition matches the BGP neighbor IP exactly. Also, apply the policy inbound, not outbound.

Troubleshooting with This Command

When troubleshooting BGP path selection issues, the 'set local-preference' command is often a suspect. Start by verifying that the route-policy is correctly applied to the BGP neighbor using 'show running-config router bgp'. Then, check the actual local preference values on received routes with 'show bgp ipv4 unicast <prefix>'. If the expected local preference is not set, confirm that the route-policy conditions match the routes. Use 'show rpl route-policy <name>' to review the policy logic. Also, ensure that the policy is applied in the correct direction (inbound for routes received from the neighbor). Common issues include typos in neighbor addresses, missing 'endif' statements, or applying the policy outbound instead of inbound. Additionally, if multiple policies are applied, the order matters; the first matching policy's set actions take effect. Use 'show bgp policy' to see the effective policy chain. If local preference is not being set as expected, check for any 'pass' or 'drop' statements that might skip the set action. Finally, remember that local preference is only relevant within the AS; if routes are being sent to iBGP peers, ensure they are not overwritten by another policy.

CCNA Exam Tips

1.

Remember that local preference is only propagated within the AS and is not sent to external BGP peers.

2.

In CCNP exams, know that higher local preference is preferred; default is 100.

3.

Be able to write route-policies using 'set local-preference' in combination with 'if' conditions.

Common Mistakes

Forgetting to apply the route-policy to the BGP neighbor or address-family using 'neighbor x.x.x.x route-policy POLICY in'.

Setting local preference in the wrong direction (out instead of in) for inbound routes.

Using 'set local-preference' without a condition, affecting all routes unintentionally.

Platform Notes

In Cisco IOS-XR, route policies are more powerful and flexible than Cisco IOS route-maps. The 'set local-preference' command is used within a route-policy block, whereas in IOS it is used in a route-map. IOS-XR requires explicit 'endif' statements and uses a different syntax for conditions (e.g., 'if source in' vs 'match ip address'). Additionally, IOS-XR supports hierarchical policies and policy inheritance. For equivalent functionality on other platforms, Juniper uses 'set local-preference' in a policy-statement, and Arista uses 'set local-preference' in a route-map similar to IOS. Version differences: In IOS-XR 6.0 and later, the 'set local-preference' command can also be used in BGP neighbor configuration directly (e.g., 'neighbor x.x.x.x local-preference 200'), but this is less flexible than using a route-policy. Always use route-policies for complex conditions.

Practice for the CCNA 200-301

Test your knowledge with hundreds of CCNA practice questions covering all exam domains.

Practice CCNA Questions