Configuring the AS-Path attribute can prevent loop in BGP.
BGP checks the AS-Path attribute of the route sent from the peer.
If the local AS number already exists, BGP ignores the route.
Procedure
- Allow the local AS number to be repeated.
BGP uses AS numbers to detect routing loops. In Hub and Spoke
networking, if EBGP runs between a Hub-PE and a Hub-CE, the route
sent from the Hub-PE to the Hub-CE carries the AS number of the Hub-PE.
After the Hub-CE sends an Update message that contains the AS number
of the Hub-PE to the Hub-PE, the Hub-PE will deny it.
To ensure
proper route transmission in Hub and Spoke networking, configure all
the BGP peers on the path, along which the Hub-CE advertises private
network routes to the Spoke-CE, to accept the routes in which the
local AS number repeats once.
- Access the system view.
system-view
- Access the BGP view.
bgp { as-number-plain | as-number-dot }
- Access the BGP IPv4 unicast address family view.
ipv4-family
unicast
- Allow the local AS number to be repeated.
peer { ipv4-address | group-name } allow-as-loop [ number ]
Generally, a BGP device
checks the AS_Path attribute of a route sent from a peer. If the local
AS number already exists in the AS_Path attribute, BGP ignores this
route to avoid a routing loop.
In some special applications,
you can use the peer allow-as-loop command to allow the
AS_Path attributes of routes sent from the peers to contain the local
AS number. You can also set the number of times the local AS number
is repeated.
- Configure the AS-Path not to serve as one of the route
selection principles.
- Access the system view.
system-view
- Access the BGP view.
bgp { as-number-plain | as-number-dot }
- Access the BGP IPv4 unicast address family view.
ipv4-family
unicast
- Configure the AS-Path not to serve as one of the route
selection principles.
bestroute as-path-neglect
- Set a fake AS number.
Generally, a device supports only one BGP process. This means
that a device supports only one AS number. If AS numbers need to be
replaced during network migration, you can run the peer fake-as command to set a fake AS number for a specified peer to ensure
smooth network migration.
- Access the system view.
system-view
- Access the BGP view.
bgp { as-number-plain | as-number-dot }
- Set a fake AS number.
peer { ipv4-address | group-name } fake-as { as-number-plain | as-number-dot }
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.
This command applies to only EBGP peers.
- Substitute the AS number in the AS-Path.
If the configuration with the peer substitute-as command is not correct, the command may cause routing loops.
- Access the system view.
system-view
- Access the BGP view.
bgp { as-number-plain | as-number-dot }
- Access the Virtual Private Network (VPN) instance view.
ipv4-family
unicast vpn-instance vpn-instance-name
- Substitute the AS number in the AS-Path.
peer { ipv4-address | group-name } substitute-as
After this command is used, if the AS-Path contains the AS
number of the peer, you can substitute the local AS number for the
AS number of the peer before advertising the peer.
- Configure the AS-Path to carry only the public AS number.
- Access the system view.
system-view
- Access the BGP view.
bgp { as-number-plain | as-number-dot }
- Access the BGP IPv4 unicast address family view.
ipv4-family
unicast
- Configure the AS-Path to carry only the public AS number.
peer { ipv4-address | group-name } public-as-only
In general, the number of the AS ranges
from 1 to 65535. The number of the public AS ranges from 1 to 64511,
and the number of the private AS ranges from 64512 to 65534. 65535
is used as the reserved AS number in certain circumstances.
The number of the public AS can be used on the Internet, because
Internet addresses are managed and assigned by the Internet Assigned
Number Authority (IANA). The number of the private AS cannot be advertised
to the Internet and is used only in the internal routing domain.
BGP carries an AS number (either public or private) when it advertises
routes. In certain cases, the number of the private AS does not need
to be transmitted. You can then configure the AS-Path to carry only
the public AS number with this command.
This command applies
to only EBGP peers.
- Configure the maximum number of AS numbers in the AS_Path
attribute.
- Access the system view.
system-view
- Access the BGP view.
bgp { as-number-plain | as-number-dot }
- Set the maximum number of AS numbers in the AS_Path
attribute.
as-path-limit as-path-limit-num
By default, the maximum number
of AS numbers in the AS_Path attribute is 255.
After the as-path-limit command is configured, a router checks whether the number
of AS numbers in the AS-Path attribute of the incoming route exceeds
the maximum value. If the number of AS numbers exceeds the maximum
value, the local router discards the route. Therefore, if the maximum
number of AS numbers in the AS-Path attribute is set too small, routes
are lost.
- Disable the function of checking the first AS number in
the AS_Path list that is carried in the Update message sent by the
EBGP peer.
- Access the system view.
system-view
- Access the BGP view.
bgp { as-number-plain | as-number-dot }
- Disable the function of checking the first AS number
in the AS_Path list that is carried in the Update message sent by
the EBGP peer.
undo
check-first-as
By default, BGP
checks the first AS number in the AS_Path list that is carried in
the Update message sent by the EBGP peer. If only the first AS number
indicates the AS where the EBGP peer locates, the Update message is
accepted. Otherwise, the Update message is denied, and the EBGP connection
goes Down.
After the undo check-first-as command is configured, there is a greater possibility of
routing loops. Therefore, use the command with caution.
After configurations are modified, you need to run the refresh bgp command.