The preference command configures the preferences for external, internal, and local routes. You can configure different preferences for BGP routes in the different address family views.
The undo preference command restores the default value.
By default, the preference values of EBGP external routes, IBGP internal routes, and BGP local routes are all 255.
preference external internal local [ route-policy route-policy-name ]
preference route-policy route-policy-name
undo preference
| Parameter | Description | Value |
|---|---|---|
| external | Specifies the protocol preference of the EBGP external routes. External routes are the optimal routes learned from a peer outside the AS. | It is an integer that ranges from 1 to 255. The smaller the value is, the higher the preference is. |
| internal | Specifies the preference for IBGP internal routes. Internal routes are the optimal routes learned from other peers within the same AS. | It 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:
|
It 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 the 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-VPN instance IPv4 address family view, BGP-VPN instance IPv6 address family view, BGP-IPv6 unicast address family view, BGP-IPv4 unicast address family view, BGP-IPv4 multicast 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 that 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.
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
If the preference command is used to set route preference, a Route-Policy needs to be created in advance.
Precautions
Currently, the peer route-policy command cannot be used to apply a route-policy to setting 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.
<sysname> 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
...
<sysname> 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
...
[sysname-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
...
[sysname-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
...
# Consider the BGP view as an example. The preference of IBGP routes is higher than the routes learned from IGP. So, you need to configure a lower preference administrative value.
<sysname> system-view
[sysname] bgp 100
[sysname-bgp] ipv4-family unicast
[sysname-bgp-af-ipv4] preference 2 2 20
# Set the preference of a route with the prefix of 10.1.0.0/16 to 100.
<sysname> system-view
[sysname] ip ip-prefix aa permit 10.1.0.0 16
[sysname] route-policy bb permit node 10
[sysname-route-policy] if-match ip-prefix aa
[sysname-route-policy] apply preference 100
[sysname-route-policy] quit
[sysname] bgp 100
[sysname-bgp] ipv4-family unicast
[sysname-bgp-af-ipv4] preference route-policy bb