The preference command configures the protocol preferences for external routes, internal routes, aggregated routes, and crossed routes.
The undo preference command restores the default protocol preferences.
By default, the protocol preferences of external routes, internal routes, aggregated routes, and crossed routes are all 255.
preference { external internal local | route-policy route-policy-name }
preference external internal local route-policy route-policy-name
undo preference
Parameter | Description | Value |
---|---|---|
external | Specifies the protocol preference for external routes. An external route is the optimal route learned from an EBGP peer outside the local AS. |
The value is an integer that ranges from 1 to 255. The smaller the value is, the higher the preference is. |
internal | Specifies the protocol preference for internal routes. An internal route is a route learned from an IBGP peer inside the local AS. |
The value is an integer that ranges from 1 to 255. The smaller the value is, the higher the preference is. |
local | Specifies the protocol preference for aggregated
and crossed routes. This parameter takes effect for the following
routes:
|
The value is an integer that ranges from 1 to 255. The smaller the value is, the higher the preference is. |
route-policy route-policy-name | Specifies the name of a route-policy. | The name is a string of 1 to 40 case-sensitive characters, with spaces not supported. When double quotation marks are used around the string, spaces are allowed in the string. |
BGP view, BGP-IPv4 unicast address family view, BGP-IPv4 multicast address family view, BGP-VPN instance IPv4 address family view, BGP-IPv6 unicast address family view, BGP-VPN instance IPv6 address family view
Usage Scenario
Running the preference command to set protocol preferences for BGP routes affects route selection among BGP routes and routes of other routing protocols.
After a route-policy is configured on a device, the device sets preferences only for the routes received from peers, which meet the matching rules. The routes that do not meet the rules use the default preference.
The smaller the preference value, the higher the preference.
Different protocol preferences can be configured for BGP routes in different address family views.
If both external internal local and route-policy route-policy-name are specified in the command, the priority of the routes that match the route-policy is set based on the route-policy, and the priorities of other routes are set based on the external internal local configuration.
Prerequisites
Create the route-policy first if the preference command uses the route-policy to set preferences.
Perform the following steps when the route-policy is used to set preferences:
Use the route-policy command to create the route-policy, and enter the route-policy view.
Configure the if-match clause to set the matching rules for routes. The relationship between the if-match clauses in a node of a route-policy is "AND". A route must match all the rules before the action defined by the apply clause is taken. If no if-match clause is specified, all routes will match the node in the route-policy.
Use the apply preference command to set preferences for routes that pass the filtering.
Precautions
Currently, the peer route-policy command cannot be used to apply a route-policy to set preferences for BGP routes.
The preference command cannot configure the preference for routes imported using the network command or the import-route command. The preference for these routes is 0.
Creating a route-policy before it is referenced is recommended. By default, nonexistent route-policies cannot be referenced using the command. If the route-policy nonexistent-config-check disable command is run in the system view and a nonexistent route-policy is referenced using the current command, the configured priority is set for all routes; if no priority is configured, the default priority is set for the routes.
<HUAWEI> display bgp routing-table 10.0.0.0
BGP local router ID : 192.168.2.4
Local AS number : 200
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.0.0.0/8:
Aggregated route
Route Duration: 04h50m46s
Direct Out-interface: NULL0
Original nexthop: 127.0.0.1
Qos information : 0x0
AS-path {65001 10 100}, origin incomplete, pref-val 0, valid, local, best, select, active, pre 255
Aggregator: AS 200, Aggregator ID 192.168.2.4, Atomic-aggregate
Advertised to such 3 peers:
10.1.7.2
172.16.1.2
192.168.1.2
...
<HUAWEI> display bgp routing-table 10.0.0.0
BGP local router ID : 192.168.2.4
Local AS number : 200
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.0.0.0/8:
Summary automatic route
Route Duration: 04h50m46s
Direct Out-interface: NULL0
Original nexthop: 127.0.0.1
Qos information : 0x0
AS-path {65001 10 100}, origin incomplete, pref-val 0, valid, local, best, select, active, pre 255
Aggregator: AS 200, Aggregator ID 192.168.2.4, Atomic-aggregate
Advertised to such 3 peers:
10.1.7.2
172.16.1.2
192.168.1.2
...
[HUAWEI-diagnose] display bgp vpnv4 vpn-instance vrf routing-table 172.16.17.161
BGP local router ID : 10.17.0.17
Local AS number : 100
VPN-Instance vrf, Router ID 10.17.0.17:
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 172.16.17.161/32:
Remote-Cross route
Label information (Received/Applied): 155665/NULL
From: 10.216.0.1 (10.17.0.9)
Route Duration: 3d04h26m28s
Relay Tunnel Out-Interface: Vlanif100
Relay token: 0x24e7
Relay Tunnel Key: 7
Original nexthop: 10.216.0.1
Qos information : 0x0
Ext-Community:RT <10 : 10>
AS-path 100, origin incomplete, localpref 150, pref-val 1, valid, internal, best, select, active, pre 255, IGP cost 1
...
[HUAWEI-diagnose] display bgp vpnv4 vpn-instance vrf1 routing-table 10.2.2.0
BGP local router ID : 10.1.1.1
Local AS number : 100
VPN-Instance vrf1, Router ID 10.1.1.1:
Paths: 1 available, 1 best, 1 select
BGP routing table entry information of 10.2.2.0/24:
Local-Cross route(via VPN-Instance vrf2)
Route Duration: 00h26m00s
Direct Out-interface: Vlanif40
Original nexthop: 10.2.2.2
Qos information : 0x0
Ext-Community:RT <100 : 1>
AS-path Nil, origin incomplete, MED 0, pref-val 0, valid, local, best, select, active, pre 255
...