BGP 选路忽略 AS-PATH
BGP 选路忽略 AS-PATH
功能简介
在 BGP 协议中,路由选择过程中,默认会通过多个路由属性算法来选择最佳路径。其中,AS-PATH 长度的比较是一个关键步骤。通常,AS-PATH 越短,表示路径越短,经过的 AS 数目越少,延迟和跳数更低,通常会被认为是性能更好的路径。
然而在某些场景下,AS-PATH 的长度可能并不反映网络的实际性能或可用性,管理员可能希望优先选择其他路由属性,如 localpref(local preference)、MED 或 IGP(内部网关协议)度量。
启用bestpath-as-path-ignore功能,可以使 BGP 在选择最佳路径时跳过对 AS-PATH 长度的比较,而将其他路由属性(如 localpref)作为决定因素,从而根据更合适的标准进行路径选择。
配置方法
config router bgp
set bestpath-as-path-ignore [enable | disable]
end网络拓扑
FGT-1(AS 65001):与外部网络和多个本地路由器(如 FGT-2)建立 eBGP 邻居。
FGT-2(AS 65006):与 FGT-1(AS 65001)和外部 AS 65007 建立 eBGP 邻居。
FGT-1 与外部 AS 65007 之间存在多个 BGP 路径,有的路径的 AS-PATH 较短,而有的路径的 AS-PATH 较长(如通过其他 AS 进行路径预处理)。
FGT-2 上,有两条路径到达 77.77.77.0/24 网络:
- 路径 1:通过 101.101.101.1,AS-PATH 为 65001 65007(长度为 2),localpref 为 100。
- 路径 2:通过 201.201.201.1,AS-PATH 为 65001 65002 65007(长度为 3),localpref 为 200。
在默认情况下,BGP 会选择路径 1,因为 AS-PATH 较短。然而,通过启用
bestpath-as-path-ignore命令后,BGP 将忽略 AS-PATH 长度的比较,而选择路径 2,因为路径 2 的 localpref(200)高于路径 1 的 localpref(100)。FGT-2 # get router info bgp network 77.77.77.0/24 VRF 0 BGP routing table entry for 77.77.77.0/24 Paths: (2 available, best #1, table Default-IP-Routing-Table) Original VRF 0 65001 65007 # Shorter path (length 2) 101.101.101.1 from 101.101.101.1 (19.19.19.19) Origin IGP metric 0, localpref 100, valid, external, best Last update: Tue Aug 26 12:15:57 2025 Original VRF 0 65001 65002 65007 # Longer path (length 3) 201.201.201.1 from 201.201.201.1 (19.19.19.19) Origin IGP metric 0, localpref 200, valid, external Last update: Tue Aug 26 12:15:57 2025此时需要 BGP 选择一个路径时,不仅仅依赖 AS-PATH 长度,还能够根据其他属性(如 localpref 或 MED)来进行优化选择。
验证步骤
在 FGT-2 上启用
set bestpath-as-path-ignore命令,以忽略 AS-PATH 长度,并优先选择 localpref 更高的路径。config router bgp set as 65006 set bestpath-as-path-ignore enable config neighbor edit "101.101.101.1" set remote-as 65001 set local-preference 200 ←---设置localpref较高的路径 next end end在启用命令后,我们查看 BGP 路由表的变化。可以看到启用
bestpath-as-path-ignore后,BGP 选择了 localpref 更高的路径,即使其 AS-PATH 更长。fgt-2 # get router info bgp network 77.77.77.0/24 VRF 0 BGP routing table entry for 77.77.77.0/24 Paths: (2 available, best #2, table Default-IP-Routing-Table) Original VRF 0 65001 65007 # Shorter path 101.101.101.1 from 101.101.101.1 (19.19.19.19) Origin IGP metric 0, localpref 100, valid, external Last update: Tue Aug 26 12:15:57 2025 Original VRF 0 65001 65002 65007 # Longer path now best due to higher local pref 201.201.201.1 from 201.201.201.1 (19.19.19.19) Origin IGP metric 0, localpref 200, valid, external, best Last update: Tue Aug 26 12:15:57 2025