BGP prefers the route with the highest Local_Pref during BGP route selection.
The Local_Pref attribute is used to determine the optimal route when traffic leaves an AS. The Local_Pref attribute is available only to IBGP peers and is not advertised to other ASs.
Table 1 lists two methods to modify the Local_Pref value.
Method |
Usage Scenario |
---|---|
Run the default local-preference command. |
This method sets a default Local_Pref for the routes that the local device advertises to IBGP peers. |
Configure an import or export policy and run the apply local-preference command to configure an apply clause for the policy. |
This method sets different Local_Pref values for different routes that the local device advertises to IBGP peers. NOTE:
If both the methods are used, the method with the import policy takes effect if routes match the conditions specified in the apply local-preference command and the policy. |
The following example shows how the Local_Pref value is used during route selection. In Figure 1, both ISP1 and ISP2 advertise the routes 10.11.0.0/16 and 10.22.0.0/16 to AS 65001.
Scenario 1: When no Local_Pref value is configured on Device A and Device B, check the BGP routing tables of Device A and Device B.
[~DeviceA] display bgp routing-table BGP Local router ID is 192.168.2.3 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/30 0.0.0.0 0 0 i *>i 10.1.2.0/30 10.1.3.2 0 100 0 i *> 10.11.0.0/16 10.1.1.1 0 100 10i * i 10.1.2.1 100 0 200 10i *> 10.22.0.0/16 10.1.1.1 0 100 10i * i 10.1.2.1 100 0 200 10i
The BGP routing table of Device A shows that Device A receives the routes 10.11.0.0/16 and 10.22.0.0/16 from ISP1 and Device B. Check the information about the route 10.11.0.0/16 on Device A.
[~DeviceA] display bgp routing-table 10.11.0.0 BGP local router ID : 192.168.2.3 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.1.1 (192.168.2.5) Route Duration: 04h41m03s Direct Out-interface: GigabitEthernet0/1/1 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, pref-val 0, valid, external, best, select, active, pre 255 Advertised to such 2 peers: 10.1.3.2 10.1.4.2 BGP routing table entry information of 10.11.0.0/16: From: 10.1.3.2 (192.168.2.2) Route Duration: 01h42m40s Relay IP Nexthop: 10.1.3.2 Relay IP Out-Interface: GigabitEthernet0/1/3 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, not preferred for peer type Not advertised to any peer yet
The preceding command output shows that the route learned from ISP1 is selected as the optimal route because it is an EBGP route and the route learned from Device B is an IBGP route. Table 2 shows the route attribute comparison of the routes 10.11.0.0/16 learned from ISP1 and Device B.
Route Attribute |
Route Learned from ISP1 |
Route Learned from Device B |
Comparison |
---|---|---|---|
PrefVal |
0 |
0 |
The same. |
Local_Pref |
- |
100 |
The same. NOTE:
If a route does not carry Local_Pref, the default value 100 takes effect. |
Route type |
Learned from a peer |
Learned from a peer |
The same. |
AIGP |
- |
- |
The same. |
AS_Path |
100 10 |
200 10 |
The same length. |
Origin |
IGP |
IGP |
The same. |
MED |
- |
- |
The same. |
Peer type |
EBGP |
IBGP |
Route 10.11.0.0/16 learned from ISP1 is optimal. |
The route selection process on Device B is the same as that on Device A. Then, Device A and Device B advertise the optimal routes to Device C. Check the routing table of Device C.
[~DeviceC] display bgp routing-table Total Number of Routes: 6 BGP Local router ID is 192.168.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.4.1 0 100 0 i *>i 10.1.2.0/30 10.1.5.1 0 100 0 i *>i 10.11.0.0/16 10.1.2.1 100 0 200 10i * i 10.1.1.1 100 0 100 10i *>i 10.22.0.0/16 10.1.2.1 100 0 200 10i * i 10.1.1.1 100 0 100 10i
The preceding command output shows that Device C selects the routes advertised by Device B.
Check the reason why the routes learned from Device A are not selected on Device C. The route 10.11.0.0/16 is used as an example.
[~DeviceC] display bgp routing-table 10.11.0.0 BGP local router ID : 192.168.2.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.5.1 (192.168.2.2) Route Duration: 00h12m46s Relay IP Nexthop: 10.1.5.1 Relay IP Out-Interface: GigabitEthernet0/1/1 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 100, pref-val 0, valid, internal, best, select, active, pre 255 Not advertised to any peer yet BGP routing table entry information of 10.11.0.0/16: From: 10.1.4.1 (192.168.2.3) Route Duration: 00h17m30s Relay IP Nexthop: 10.1.4.1 Relay IP Out-Interface: GigabitEthernet0/1/0 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, not preferred for router ID Not advertised to any peer yet
The preceding command output shows that Device C selects the route 10.11.0.0/16 learned from Device B because the router ID (192.168.2.2) of Device B is smaller than that (192.168.2.3) of Device A. Table 3 shows the route attribute comparison of the routes 10.11.0.0/16 learned from Device A and Device B.
Route Attribute |
Route Learned from Device A |
Route Learned from Device B |
Comparison |
---|---|---|---|
PrefVal |
0 |
0 |
The same. |
Local_Pref |
100 |
100 |
The same. |
Route type |
Learned from a peer |
Learned from a peer |
The same. |
AIGP |
- |
- |
The same. |
AS_Path |
100 10 |
200 10 |
The same length. |
Origin |
IGP |
IGP |
The same. |
MED |
- |
- |
The same. |
Peer type |
IBGP |
IBGP |
The same. |
IGP cost |
- |
- |
The same. |
Cluster_List |
- |
- |
The same length. |
Router ID |
192.168.2.3 |
192.168.2.2 |
Route 10.11.0.0/16 learned from Device B is optimal. |
Scenario 2: The administrator of AS 65001 requires that ISP1 be active and ISP2 be backup for the traffic to 10.11.0.0/16 and 10.22.0.0/16.
To meet the preceding requirements, run the default local-preference command on Device A to increase the Local_Pref values of the routes learned from Device A. This configuration ensures that the routes learned from ISP1 are selected as the optimal routes. Detailed configurations are as follows:
# bgp 65001 # ipv4-family unicast default local-preference 120 //Set the Local_Pref of the routes to be advertised to 120. #
Run the display bgp routing-table [ ip-address ] command to check the configurations.
# Display the routing table of Device A.
[~DeviceA] display bgp routing-table BGP Local router ID is 192.168.2.3 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 4 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/30 0.0.0.0 0 0 i *>i 10.1.2.0/30 10.1.3.2 0 100 0 i *> 10.11.0.0/16 10.1.1.1 0 100 10i *> 10.22.0.0/16 10.1.1.1 0 100 10i
The preceding command output shows that Device A selects the routes learned from ISP1.
# Display the routing table of Device B.
[~DeviceB] display bgp routing-table BGP Local router ID is 192.168.2.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.3.1 0 120 0 i *> 10.1.2.0/30 0.0.0.0 0 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i * 10.1.2.1 0 200 10i *>i 10.22.0.0/16 10.1.1.1 120 0 100 10i * 10.1.2.1 0 200 10i
The preceding command output shows that Device B selects the routes learned from Device A. Device B does not advertise the routes learned from ISP2 to its IBGP peers because those routes are not selected.
# Display detailed information about the route 10.11.0.0/16 or 10.22.0.0/16 on Device B. The route 10.11.0.0/16 is used as an example.
[~DeviceB] display bgp routing-table 10.11.0.0 BGP local router ID : 192.168.2.2 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.3.1 (192.168.2.3) Route Duration: 00h22m16s Relay IP Nexthop: 10.1.3.1 Relay IP Out-Interface: GigabitEthernet0/1/4 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 120, pref-val 0, valid, internal, best, select, active, pre 255 Advertised to such 1 peers: 10.1.2.1 BGP routing table entry information of 10.11.0.0/16: From: 10.1.2.1 (192.168.2.4) Route Duration: 00h22m23s Direct Out-interface: GigabitEthernet0/1/0 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, pref-val 0, valid, external, pre 255, not preferred for Local_Pref Not advertised to any peer yet
The preceding command output shows that the Local_Pref value of the route learned from Device A is greater than that of the route learned from ISP2 and that the route learned from Device A is selected as the optimal route. Table 4 shows the route attribute comparison of the routes 10.11.0.0/16 learned from Device A and ISP2.
Route Attribute |
Route Learned from Device A |
Route Learned from ISP2 |
Comparison |
---|---|---|---|
PrefVal |
0 |
0 |
The same. |
Local_Pref |
120 |
- |
Route 10.11.0.0/16 learned from Device A is optimal. NOTE:
If a route does not carry Local_Pref, the default value 100 takes effect. |
# Display the routing table of Device C.
[~DeviceC] display bgp routing-table Total Number of Routes: 4 BGP Local router ID is 192.168.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.4.1 0 120 0 i *>i 10.1.2.0/30 10.1.5.1 0 100 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i *>i 10.22.0.0/16 10.1.1.1 120 0 100 10i
Device C selects the routes advertised by ISP1 because Device B did not advertise the routes learned from ISP2 to Device C.
Scenario 3: The requirements of the administrator of AS 65001 are as follows:
To meet the preceding requirements, ensure that AS 65001 selects the route 10.11.0.0/16 learned from Device A and the route 10.22.0.0/16 learned from Device B. Detailed configurations are as follows:
Configurations on Device A
# bgp 65001 # ipv4-family unicast peer 10.1.1.1 route-policy rp1 import //Apply import policy named rp1 to the routes learned from 10.1.1.1 and use rp1 to modify the Local_Pref. # route-policy rp1 permit node 10 //Define the first node of rp1 and set the Local_Pref value of the route 10.11.0.0/16 to 80. if-match ip-prefix reducepref apply local-preference 80 # route-policy rp1 permit node 20 //Define the second node of rp1 and set the Local_Pref value of the route 10.22.0.0/16 to 120. if-match ip-prefix addpref apply local-preference 120 # route-policy rp1 permit node 30 //Define the third node of rp1 and allow rp1 to permit all routes. # ip ip-prefix addpref index 10 permit 10.11.0.0 16 //Configure an IP prefix list to match the route 10.11.0.0/16. ip ip-prefix reducepref index 10 permit 10.22.0.0 16 //Configure an IP prefix list to match the route 10.22.0.0/16. #
Configurations on Device B
bgp 65001 # ipv4-family unicast peer 10.1.2.1 route-policy rp2 import //Apply import policy named rp2 to the routes learned from 10.1.1.1 and use rp2 to modify the Local_Pref. # route-policy rp2 permit node 10 //Define the first node of rp2 and set the Local_Pref value of the route 10.22.0.0/16 to 200. if-match ip-prefix addpref apply local-preference 200 # route-policy rp2 permit node 20 //Define the second node of rp2 and set the Local_Pref value of the route 10.11.0.0/16 to 60. if-match ip-prefix reducepref apply local-preference 60 # route-policy rp2 permit node 30 //Define the third node of rp2 and allow rp2 to permit all routes. # ip ip-prefix addpref index 10 permit 10.22.0.0 16 //Configure an IP prefix list to match the route 10.22.0.0/16. ip ip-prefix reducepref index 10 permit 10.11.0.0 16 //Configure an IP prefix list to match the route 10.11.0.0/16. #
Run the display bgp routing-table [ ip-address ] command to check the configurations.
# Display the routing table of Device A.
[~DeviceA] display bgp routing-table BGP Local router ID is 192.168.2.3 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 5 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/30 0.0.0.0 0 0 i *>i 10.1.2.0/30 10.1.3.2 0 100 0 i *> 10.11.0.0/16 10.1.1.1 120 0 100 10i *>i 10.22.0.0/16 10.1.2.1 200 0 200 10i * 10.1.1.1 80 0 100 10i
# Display detailed information about the route 10.22.0.0/16 on Device A.
[~DeviceA] display bgp routing-table 10.22.0.0 BGP local router ID : 192.168.2.3 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.22.0.0/16: From: 10.1.3.2 (192.168.2.2) Route Duration: 00h20m12s Relay IP Nexthop: 10.1.3.2 Relay IP Out-Interface: GigabitEthernet0/1/3 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 200, pref-val 0, valid, internal, best, select, active, pre 255 Advertised to such 1 peers: 10.1.1.1 BGP routing table entry information of 10.22.0.0/16: From: 10.1.1.1 (192.168.2.5) Route Duration: 00h19m40s Direct Out-interface: GigabitEthernet0/1/1 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 80, pref-val 0, valid, external, pre 255, not preferred for Local_Pref Not advertised to any peer yet
The preceding command output shows that two routes 10.22.0.0/16 are available in the BGP routing table of Device A and that the route with next hop address 10.1.2.1 is selected because its Local_Pref (200) is greater than the Local_Pref (80) of the route with next hop address 10.1.1.1.
Table 5 shows the route attribute comparison of the routes 10.22.0.0/16 learned from ISP1 and Device B.
Route Attribute |
Route Learned from ISP1 |
Route Learned from Device B |
Comparison |
---|---|---|---|
PrefVal |
0 |
0 |
The same. |
Local_Pref |
200 |
80 |
Route 10.22.0.0/16 learned from ISP1 is optimal. |
The route with next hop address 10.1.1.1 is not optimal, and therefore, it is not advertised to Device B and Device C. In addition, the route 10.11.0.0/16 with next hop address 10.1.2.1 is not optimal on Device B, and therefore, Device B does not advertise this route to Device A and Device C. As a result, only one route 10.11.0.0/16 with next hop address 10.1.1.1 is available in the BGP routing table of Device A.
# Display the routing table of Device B.
[~DeviceB] display bgp routing-table BGP Local router ID is 192.168.2.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 5 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.3.1 0 100 0 i *> 10.1.2.0/30 0.0.0.0 0 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i * 10.1.2.1 60 0 200 10i *> 10.22.0.0/16 10.1.2.1 200 0 200 10i
# Display detailed information about the route 10.11.0.0/16 on Device B.
[~DeviceB] display bgp routing-table 10.11.0.0 BGP local router ID : 192.168.2.2 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.3.1 (192.168.2.3) Route Duration: 00h40m28s Relay IP Nexthop: 10.1.3.1 Relay IP Out-Interface: GigabitEthernet0/1/4 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 120, pref-val 0, valid, internal, best, select, active, pre 255 Advertised to such 1 peers: 10.1.2.1 BGP routing table entry information of 10.11.0.0/16: From: 10.1.2.1 (192.168.2.4) Route Duration: 00h41m00s Direct Out-interface: GigabitEthernet0/1/0 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 60, pref-val 0, valid, external, pre 255, not preferred for Local_Pref Not advertised to any peer yet
The preceding command output shows that two routes 10.11.0.0/16 are available in the BGP routing table of Device B and that the route with next hop address 10.1.1.1 is selected because its Local_Pref (120) is greater than the Local_Pref (60) of the route with next hop address 10.1.2.1. The route with next hop address 10.1.2.1 is not advertised to Device A and Device C because it is not optimal.
# Display the routing table of Device C.
[~DeviceC] display bgp routing-table Total Number of Routes: 4 BGP Local router ID is 192.168.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.4.1 0 100 0 i *>i 10.1.2.0/30 10.1.5.1 0 100 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i *>i 10.22.0.0/16 10.1.2.1 200 0 200 10i
The preceding command output shows that the next hop address of the route 10.11.0.0/16 is 10.1.1.1 and that the next hop address of the route 10.22.0.0/16 is 10.1.2.1.
To meet the preceding requirements, ensure that Device A and Device C select the routes learned from ISP1. Detailed configurations are as follows:
bgp 65001 # ipv4-family unicast peer 10.1.2.1 route-policy rp2 export # route-policy rp2 permit node 10 if-match ip-prefix addpref apply local-preference 120
Run the display bgp routing-table [ ip-address ] command to check the configurations.
# Display the routing table of Device A.
[~DeviceA] display bgp routing-table BGP Local router ID is 192.168.2.3 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *> 10.1.1.0/30 0.0.0.0 0 0 i *>i 10.1.2.0/30 10.1.3.2 0 100 0 i *> 10.11.0.0/16 10.1.1.1 0 100 10i * i 10.1.2.1 100 0 200 10i *> 10.22.0.0/16 10.1.1.1 0 100 10i * i 10.1.2.1 100 0 200 10i
The preceding command output shows that Device A selects the routes learned from ISP1.
# Display the routing table of Device B.
[~DeviceB] display bgp routing-table BGP Local router ID is 192.168.2.2 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Total Number of Routes: 6 Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.3.1 0 100 0 i *> 10.1.2.0/30 0.0.0.0 0 0 i *> 10.11.0.0/16 10.1.2.1 0 200 10i * i 10.1.1.1 100 0 100 10i *> 10.22.0.0/16 10.1.2.1 0 200 10i * i 10.1.1.1 100 0 100 10i
The preceding command output shows that Device B selects the routes learned from ISP2.
# Display the routing table of Device C.
[~DeviceC] display bgp routing-table Total Number of Routes: 6 BGP Local router ID is 192.168.2.1 Status codes: * - valid, > - best, d - damped, x - best external, a - add path, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete RPKI validation codes: V - valid, I - invalid, N - not-found Network NextHop MED LocPrf PrefVal Path/Ogn *>i 10.1.1.0/30 10.1.4.1 0 120 0 i *>i 10.1.2.0/30 10.1.5.1 0 100 0 i *>i 10.11.0.0/16 10.1.1.1 120 0 100 10i * i 10.1.2.1 100 0 200 10i *>i 10.22.0.0/16 10.1.1.1 120 0 100 10i * i 10.1.2.1 100 0 200 10i
The preceding command output shows that Device C selects the routes learned from ISP1.
# Display detailed information about the route 10.11.0.0/16 or 10.22.0.0/16 on Device C. The route 10.11.0.0/16 is used as an example.
[~DeviceC] display bgp routing-table 10.11.0.0 BGP local router ID : 192.168.2.1 Local AS number : 65001 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 10.11.0.0/16: From: 10.1.4.1 (192.168.2.3) Route Duration: 00h06m26s Relay IP Nexthop: 10.1.4.1 Relay IP Out-Interface: GigabitEthernet0/1/0 Original nexthop: 10.1.1.1 Qos information : 0x0 AS-path 100 10, origin igp, localpref 120, pref-val 0, valid, internal, best, select, active, pre 255 Not advertised to any peer yet BGP routing table entry information of 10.11.0.0/16: From: 10.1.5.1 (192.168.2.2) Route Duration: 00h08m05s Relay IP Nexthop: 10.1.5.1 Relay IP Out-Interface: GigabitEthernet0/1/1 Original nexthop: 10.1.2.1 Qos information : 0x0 AS-path 200 10, origin igp, localpref 100, pref-val 0, valid, internal, pre 255, not preferred for Local_Pref Not advertised to any peer yet
The preceding command output shows that Device C selects the routes learned from ISP1 because the Local_Pref of the routes learned from ISP1 is greater than that of the route learned from ISP2.
The preceding examples show that the modification of the Local_Pref values affects not only BGP route advertisement but also BGP route selection with an AS. We can configure Local_Pref values as required to control the forwarding path of the traffic that leaves an AS.