Configuring the AS_Path Attribute
Context
The AS_Path attribute records all 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.
By default, BGP compares the AS_Path lists of routes and prefers the route. 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.
By default, BGP detects routing loops based on 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 private AS numbers cannot 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 BGP from checking the first AS number. BGP can also check whether the first AS number in the AS_Path attribute contained in the update messages received from the specified EBGP peer or peer group is the number of the AS where the EBGP peer or peer group resides. If the function is not configured for a specified EBGP peer, the device checks whether the function is configured for the related peer group; if the function is not configured for the peer group, the device checks whether the function is configured in the BGP view.
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 matching rules.
By default, all routes meet matching rules. For details, see (Optional) Configuring if-match Clauses.
- Run apply as-path { { as-number-plain | as-number-dot } &<1-10> { additive | overwrite | delete } | none 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
The BGP-IPv4 unicast address family view is displayed.
Run ipv4-family multicast
The BGP-IPv4 multicast address family view is displayed.
Run ipv4-family vpnv4 [ unicast ]
The BGP-VPNv4 address family view is displayed.
Run ipv4-family vpn-instance vpn-instance-name
The BGP-VPN instance IPv4 address family view is displayed.
Run ipv6-family [ unicast ]
The BGP-IPv6 unicast address family view is displayed.
Run ipv6-family vpnv6 [ unicast ]
The BGP-VPNv6 address family view is displayed.
Run ipv6-family vpn-instance vpn-instance-name
The BGP-VPN instance IPv6 address family view is displayed.
- Add the AS_Path attribute to routes.
The import-route and network commands cannot be executed in the BGP-VPNv4 address family view or BGP-VPNv6 address family view.
- 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 ] [ med med | 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 peer { ipv4-address | group-name | ipv6-address } route-policy route-policy-name export
- (Optional) Run any 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 numbers are not allowed.
Run peer { group-name | ipv4-address | ipv6-address } public-as-only [ force [ replace ] [ include-peer-as ] | limited [ replace ] [ include-peer-as ] ]
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.
If the 4-byte private AS number function is enabled using the private-4-byte-as enable command, private AS numbers range from 64512 to 65534 and from 4200000000 to 4294967294 (64086.59904 to 65535.65534 in the format of x.y).
- Return to the BGP view to configure the AS_Path attribute.
- Run quit
Return to the BGP view.
- (Optional) Run any 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 } local-as { as-number-plain | as-number-dot } [ dual-as ] [ prepend-global-as ] [ prepend-local-as ]
A fake AS number is configured for an EBGP peer group.
The peer local-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.
By default, EBGP peers establish a connection using the actual AS number.
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.
Running the undo check-first-as command increases the probability of routing loops. Therefore, exercise caution when using this command.
After the configuration is complete, run the refresh bgp command in the user view if you want to check the received routes again.
Enable the device to check or disable the device from checking the first AS number in the AS_Path attribute contained in the update messages received from a specified EBGP peer or peer group.
Run peer { group-name | ipv4-address | ipv6-address } check-first-as enable
Run peer { group-name | ipv4-address | ipv6-address } check-first-as disable
By default, a device checks the first AS number in the AS_Path attribute contained in the update messages received from all EBGP peers or peer groups.
After the configuration is complete, run the refresh bgp command in the user view if you want to check the received routes again.
- Run quit
- Run commit
The configuration is committed.