Configuring the AS_Path Attribute
Context
The AS_Path attribute records all of the ASs that a route passes through from the source to the destination in the vector order. You can configure the AS_Path attribute to implement flexible route selection.
Generally, BGP compares the AS_Path lists of routes and prefers the route with the shortest AS_Path list. When the AS_Path attribute is not required in route selection, configure BGP not to compare the AS_Path lists of routes during route selection.
In most cases, BGP detects routing loops based on the AS number. However, to ensure correct route transmission on a hub-and-spoke network, you need to configure all the BGP peers that VPN routes advertised from a hub CE to a spoke CE pass through to accept the routes with a repeated AS number.
Public AS numbers can be used on the Internet, but not private AS numbers because they may cause routing loops. To prevent routing loops, configure the AS_Path attribute to carry only public AS numbers in EBGP Update messages.
When the AS_Path attribute is reconstructed or summarized routes are generated, you can set the maximum number of AS numbers in the AS_Path attribute. Then a BGP device checks whether the number of AS numbers in the AS_Path attribute of a route exceeds the maximum value. If so, the BGP device discards the route.
A device usually supports only one BGP process. This indicates that a device supports only one AS number. In some cases, for example, when network migration changes an AS number, you can set a fake AS number to ensure successful network migration.
BGP checks the first AS number in the AS_Path list that is carried in the Update message sent by an EBGP peer. If the first AS number specifies the AS where the EBGP peer resides, BGP accepts the Update message. Otherwise, BGP rejects the Update message and interrupts the EBGP connection. If you do not want BGP to check the first AS number, disable the option.
Procedure
- Run:
system-view
The system view is displayed.
- Run:
route-policy route-policy-name { deny | permit } node node
A node is configured for a route-policy, and the view of the route-policy is displayed.
- (Optional) Configure matching rules for the route-policy
to change only the community attributes of the routes that meet the
matching rules.
By default, all routes meet matching rules. For details, see (Optional) Configuring an if-match Clause.
- Run:
apply as-path { as-number-plain | as-number-dot } &<1-10> { additive | overwrite }
The AS_Path attribute is set for BGP routes.
- Run:
quit
Return to the system view.
- Run:
bgp { as-number-plain | as-number-dot }
The BGP view is displayed.
- Enter the corresponding address family view
based on network type to configure BGP devices on networks.
Run:
ipv4-family { unicast | multicast }
The IPv4 address family view is displayed.
Run:
ipv6-family [ unicast ]
The IPv6 address family view is displayed.
- Add the AS_Path attribute to routes.
- Run:
peer { ipv4-address | group-name | ipv6-address } route-policy route-policy-name export
The AS_Path attribute is added to the routes advertised to BGP peers or peer groups.
- Run:
peer { ipv4-address | group-name | ipv6-address } route-policy route-policy-name import
The AS_Path attribute is added to the routes received from BGP peers or peer groups.
- Run:
import-route protocol [ process-id ] route-policy route-policy-name
The AS_Path attribute is added to the routes imported by BGP in import mode.
- Run:
network { ipv4-address [ mask | mask-length ] | ipv6-address prefix-length } route-policy route-policy-name
The AS_Path attribute is added to the routes imported by BGP in network mode.
- Run:
- (Optional) Run one of the following commands to configure
the AS_Path attribute as required.
- Run:
bestroute as-path-ignore
BGP is configured not to compare the AS_Path attributes of routes during route selection.
By default, BGP compares the AS_Path attributes of routes during route selection.
- Run:
peer { ipv4-address | group-name | ipv6-address } allow-as-loop [ number ]
Repeated local AS numbers are allowed in routes.
By default, repeated local AS number is not allowed.
- Run:
peer { ipv4-address | group-name | ipv6-address } public-as-only [ force ]
BGP is configured to carry only public AS numbers in the AS_Path attribute in an EBGP Update message.
By default, the AS_Path attribute can carry both public and private AS numbers in an EBGP Update message.
- Return to the BGP view to configure the AS_Path attribute.
- Run:
quit
Return to the BGP view.
- (Optional) Run one of the following commands to configure the
AS_Path attribute as required.
- Run:
as-path-limit as-path-limit-num
The maximum number of AS numbers in the AS_Path attribute is set.
By default, the maximum number of AS numbers in the AS_Path attribute is 255.
- Run:
peer { ipv4-address | group-name | ipv6-address } fake-as { as-number-plain | as-number-dot } [ prepend-global-as ]
The peer fake-as command can be used to hide the actual AS number of a BGP device. EBGP peers in other ASs will use the fake AS number of this BGP device to set up EBGP peer relationships with this device.
A fake AS number is configured for an EBGP peer group.
By default, EBGP peers establish a connection using a real AS number.
Running the undo check-first-as command increases the probability of routing loops. Therefore, exercise caution when using this command.
- Run:
undo check-first-as
BGP is configured not to check the first AS number in the AS_Path list that is carried in the Update message sent by an EBGP peer.
By default, BGP checks the first AS number in the AS_Path list that is carried in the Update message sent by an EBGP peer.
NOTE:
When BGP is disabled from checking the first AS number, run the refresh bgp command in the user view if you want BGP to check the first AS number of received routes.
- Run: