附加 AS-Path
2026/4/1大约 3 分钟
附加 AS-Path
功能简介
本文主要介绍在 BGP 多链路(如连接多个 ISP)场景中,如何通过 AS-PATH prepend 影响入向(回程)流量路径。
典型需求是将互联网出口设计为主备链路:
- 主线路(Primary ISP)作为优先路径。
- 备线路(Secondary ISP)仅在主线路故障时承载流量。
在此类场景中,仅在 ISP 侧设置 Local Preference 可能无法完全达到预期。因为 Local Preference 是非传递属性,只在各自 AS 内部生效,不会跨 AS 传播到其他 ISP。
因此可使用 AS-PATH(传递属性)进行路径影响:在向备线路通告前缀时,追加多个本地 AS 号,使该路径更“长”,从而降低其被优选概率。
网络拓扑

使用要点
- 互联网侧路由器的回程选路可通过
AS-PATH属性进行影响。 - BGP 默认优选 AS-PATH 更短的路径。
- 在向 Secondary ISP 通告
93.184.216.34/32时进行 prepend,可以让回程更倾向 Primary ISP,而不是依赖 ISP 侧 Local Preference。 - Secondary ISP(AS65201)到达
93.184.216.34/32时,会因 Primary ISP 宣告路径更短而优选经 AS65101。 - 若需同时控制 FortiGate 出向优先主线路,可在本地对 Primary ISP 邻居设置更高
Local Preference或Weight。
配置步骤
示例参数如下:
- FortiGate 本地 AS:
65301 - 主线路邻居(WAN1):
202.1.1.2(AS65101) - 备线路邻居(WAN2):
202.2.2.2(AS65201) - 对外发布前缀(DMZ):
93.184.216.34/32(通过 Loopback 模拟)
接口配置(WAN1/WAN2/DMZ)。
config system interface edit "port2" set vdom "root" set ip 202.1.1.1 255.255.255.240 set allowaccess ping set type physical set alias "WAN1" next edit "port3" set vdom "root" set ip 202.2.2.1 255.255.255.240 set allowaccess ping set type physical set alias "WAN2" next edit "DMZ" set vdom "root" set ip 93.184.216.34 255.255.255.255 set allowaccess ping set type loopback next end备线路出站 route-map(AS-PATH prepend)。
config router route-map edit "Secondary_ISP" config rule edit 1 set set-aspath "65301 65301 65301" next end next end主线路入站 route-map(提高本地优先级)。
config router route-map edit "Primary_ISP" config rule edit 1 set set-local-preference 200 next end next end在 BGP 邻居上应用 route-map。
config router bgp set as 65301 set router-id 3.3.3.3 config neighbor edit "202.1.1.2" set remote-as 65101 set route-map-in "Primary_ISP" next edit "202.2.2.2" set remote-as 65201 set route-map-out "Secondary_ISP" next end config network edit 1 set prefix 93.184.216.34 255.255.255.255 next end end
验证步骤
变更前(未应用 prepend)
在 Secondary ISP 路由器查看,此时 93.184.216.34/32 的最佳路径为 202.2.2.1(经 Secondary ISP)。
ISP2-R1 # get router info bgp network
BGP table version is 8, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight RouteTag Path
*> 93.184.216.34/32 202.2.2.1 0 0 0 0 65301 i
* i 101.1.1.1 0 100 0 0 65101 65301 i
*> 202.2.2.0/28 0.0.0.0 100 32768 0 i变更后(应用 prepend)
应用 prepend 后,最佳路径切换为 101.1.1.1(经 Primary ISP),并且备线路路径 AS-PATH 变长(出现多个 65301)。
ISP2-R1 # get router info bgp network
BGP table version is 10, local router ID is 2.2.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight RouteTag Path
*>i93.184.216.34/32 101.1.1.1 0 100 0 0 65101 65301 i
* 202.2.2.1 0 0 0 0 65301 65301 65301 65301 i
*> 202.2.2.0/28 0.0.0.0 100 32768 0 i总结
AS-PATH prepend主要用于影响入向(回程)流量。- 本地出向优选应配合
Local Preference/Weight控制。 - 变更后建议执行软重配或路由刷新并复核路由表。
- 建议在维护窗口先小范围验证,避免生产回程路径抖动。