多个本地 AS 的配置和通告
多个本地 AS 的配置和通告
网络拓扑

例如同一数据中心的双 Hub 场景:
- 两个 Hub(FW1 与 FW2)与 Spoke 建立 IBGP 邻居(使用 AS 10086),并做路由反射。
- 两个 Hub 之间通过 EBGP(AS 使用 10000 和 20000)备份 IBGP 路由。
- 此例为了简要说明问题,使用简化拓扑。
FW1 与 FW2 在
config router bgp下(以下简称“全局配置”)配置的 AS 均为 10086,用于维护同一个 AS 下的 IBGP 邻居路由。FW1: config router bgp set as 10086 set router-id 202.103.12.1 end FW2: config router bgp set as 10086 set router-id 202.103.12.2 endFW1 与 FW2 建立 EBGP 邻居,FW1 在
config neighbor下配置 FW2 的 EBGP 邻居,local-as为 10000,remote-as为 20000,并宣告自身的路由10.10.1.0/24。config router bgp config neighbor edit "202.103.12.2" set soft-reconfiguration enable set interface "port4" set remote-as 20000 set local-as 10000 set update-source "port4" next end config network edit 1 set prefix 10.10.1.0 255.255.255.0 next end endFW2 在
config neighbor下配置 FW1 的 EBGP 邻居,local-as为 20000,remote-as为 10000,并宣告自身的路由10.10.2.0/24。config router bgp config neighbor edit "202.103.12.1" set soft-reconfiguration enable set interface "port4" set remote-as 10000 set local-as 20000 set update-source "port4" next end config network edit 1 set prefix 10.10.2.0 255.255.255.0 next end end
问题现象
FW1 与 FW2 的 EBGP 邻居建立完成。
查看 FW1 的 BGP 邻居状态和 BGP 路由表,邻居已建立,但学不到任何路由。
FW1 # get router info bgp summary VRF 0 BGP router identifier 202.103.12.1, local AS number 10086 BGP table version is 2 2 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 202.103.12.2 4 20000 84 83 2 0 0 00:13:31 0 Total number of neighbors 1 FW1 # get router info bgp network VRF 0 BGP table version is 2, local router ID is 202.103.12.1 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 *> 10.10.1.0/24 0.0.0.0 100 32768 0 i <-/1> Total number of prefixes 1查看 FW2 的 BGP 邻居状态和 BGP 路由表,邻居已建立,但学不到任何路由。
FW2 # get router info bgp summary VRF 0 BGP router identifier 202.103.12.2, local AS number 10086 BGP table version is 3 2 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 202.103.12.1 4 10000 112 128 3 0 0 00:13:48 0 Total number of neighbors 1 FW2 # get router info bgp network VRF 0 BGP table version is 3, local router ID is 202.103.12.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 *> 10.10.2.0/24 0.0.0.0 100 32768 0 i <-/1> Total number of prefixes 1在 FW2 上查看向 FW1 发送的 BGP 路由,可以看到 FW2 向 FW1 宣告了自身路由
10.10.2.0/24。FW2 # get router info bgp neighbors 202.103.12.1 advertised-routes VRF 0 BGP table version is 3, local router ID is 202.103.12.2 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight RouteTag Path *> 10.10.2.0/24 202.103.12.2 100 32768 0 i <-/-> Total number of prefixes 1在 FW1 上查看从 FW2 接收的 BGP 路由,可以看到 FW1 从 FW2 收到了路由
10.10.2.0/24,但并未放入 BGP 路由表。该路由的 AS Path 为20000 10086,10086为 FW2 在全局(config router bgp)下配置的local-as。FW1 # get router info bgp neighbors 202.103.12.2 received-routes VRF 0 BGP table version is 2, local router ID is 202.103.12.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight RouteTag Path *> 10.10.2.0/24 202.103.12.2 0 0 20000 10086 i <-/-> Total number of prefixes 1
问题原因
如果
config neighbor下没有配置local-as,EBGP 会以 AS 路径长度为 1 的方式公布源自其 AS 内的路由,只列出在 BGP 全局配置下指定的 AS 号。当
config neighbor下的local-as设置了 AS 号(此例中为 20000),默认配置下,BGP 会将其作为全局配置的 AS 号(此例中为 10086)的前缀,从而导致 FW2 发布给 FW1 的路由的 AS Path 变为20000 10086。同理,如果路由是从一个 EBGP 邻居学到,发布给另一个 EBGP 邻居,则会 AS Path 长度会变成 3。例如 FW2 从另一个 EBGP 邻居(AS 30000)学到的路由发送给 FW1,在 FW1 上看到的 AS Path 为
20000 10086 30000。在 FW1 上查看 BGP Debug 信息,可以看到 FW1 收到 FW2 发布的路由
10.10.2.0/24,但 AS Path 为20000 10086,其中包含在全局配置中设置的 AS 10086,根据 BGP 防环机制,FW1 将该路由丢弃(Prefix 10.10.2.0/24 path_id 0 denied due to as-path contains our own AS)。diagnose ip router bgp set-filter neighbor 202.103.12.2 diagnose ip router bgp filters enable diagnose ip router bgp level info diagnose ip router bgp all enable FW1# BGP: 202.103.12.2-Outgoing [DECODE] Msg-Hdr: type 2, length 51 BGP: 202.103.12.2-Outgoing [DECODE] Update: Starting UPDATE decoding... Bytes To Read (32), msg_size (32) BGP: 202.103.12.2-Outgoing [DECODE] Update: NLRI Len(4) BGP: 202.103.12.2-Outgoing [FSM] State: Established Event: 27 BGP: 202.103.12.2-Outgoing [RIB] Update: Prefix 10.10.2.0/24 path_id 0 denied due to as-path contains our own ASFW2 学不到 FW1 发布的路由
10.10.1.0/24也是同样的原因。
解决方法
local-as-replace-as(推荐)
重要
local-as-replace-as与local-as-no-prepend都需要在config router bgp下配置了local-as,且与全局(config router bgp)下配置的 AS 号不一样时才能配置。
在 FW2 上的 EBGP 邻居配置中,开启
local-as-replace-as。开启后,FW2 会使用config neighbor下配置的local-as替换在全局(config router bgp)下配置的 AS 号。config router bgp config neighbor edit "202.103.12.1" set local-as-replace-as enable next end end在 FW1 上查看收到的 BGP 路由,FW1 将收到 AS Patch 长度为 1 的路由,如下所示,AS Patch 为
20000,此为 FW2 在config neighbor下配置的local-as,FW2 没有添加在全局(config router bgp)下配置的 AS 号10086。重要
local-as-replace-as只会在出方向使用config neighbor下配置的local-as替换全局(config router bgp)下配置的 AS 号,已有的 AS Path 不会更改。FW1 # get router info bgp neighbors 202.103.12.2 received-routes VRF 0 BGP table version is 3, local router ID is 202.103.12.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight RouteTag Path *> 10.10.2.0/24 202.103.12.2 0 0 20000 i <-/-> Total number of prefixes 1在 FW1 上查看 BGP 路由表,从 FW2 学习到的路由
10.10.2.0/24已被正确加载,并添加了自己在config neighbor下配置的local-as号10000。FW1 # get router info bgp network VRF 0 BGP table version is 3, local router ID is 202.103.12.1 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 *> 10.10.1.0/24 0.0.0.0 100 32768 0 i <-/1> *> 10.10.2.0/24 202.103.12.2 0 0 0 10000 20000 i <-/1> Total number of prefixes 2在 FW1 上查看路由表中的 BGP 路由,从 FW2 学习到的 EBGP 路由被正确加载。
FW1 # get router info routing-table bgp Routing table for VRF=0 B 10.10.2.0/24 [20/0] via 202.103.12.2 (recursive is directly connected, port4), 00:07:42, [1/0]同理,在 FW1 上的 EBGP 邻居中开启
local-as-replace-as,FW2 也可以正常学习到 FW1 发布的路由。
6.附加测试local-as-no-prepend:在 FW1 的 EBGP 邻居配置中,开启local-as-no-prepend,FW1 将不会在 BGP 路由表中添加自己在config neighbor中配置的local-as。
重要
local-as-no-prepend作用于入方向,例如 FGT 在与 EBGP 邻居 A(配置了local-as),开启local-as-no-prepend后,向 EBGP 邻居 B(未配置local-as)转发通告 A 的 EBGP 路由时,不会在 AS Path 中加上与 EBGP 邻居 A 配置的local-as。
config router bgp
config neighbor
edit "202.103.12.2"
set local-as-no-prepend enable
next
end
end
FW1 # get router info bgp network
VRF 0 BGP table version is 5, local router ID is 202.103.12.1
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
*> 10.10.1.0/24 0.0.0.0 100 32768 0 i <-/1>
*> 10.10.2.0/24 202.103.12.2 0 0 0 20000 i <-/1>
Total number of prefixes 2allowas-in-enable
恢复默认配置(在 FW1 和 FW2 上禁用
local-as-replace-as)。在 FW1 上的 EBGP 邻居配置中,开启
allowas-in-enable。开启后,FW1 会允许 AS Path 包含自身 AS 号的 BGP 路由加载(EBGP 防环失效)。config router bgp config neighbor edit "202.103.12.2" set allowas-in-enable enable set allowas-in 3 //默认配置,允许自身AS号在AS Path中出现的最大次数// next end在 FW1 上查看从 FW2 接收的 BGP 路由,可以看到 FW1 从 FW2 收到了路由
10.10.2.0/24。该路由的 AS Path 为20000 10086,10086为 FW2 在全局(config router bgp)下配置的local-as。FW1 # get router info bgp neighbors 202.103.12.2 received-routes VRF 0 BGP table version is 6, local router ID is 202.103.12.1 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight RouteTag Path *> 10.10.2.0/24 202.103.12.2 0 0 20000 10086 i <-/-> Total number of prefixes 1在 FW1 上查看 BGP 路由表,从 FW2 学习到的路由
10.10.2.0/24已被正确加载,并添加了自己在config neighbor下配置的local-as号10000。FW1 # get router info bgp network VRF 0 BGP table version is 6, local router ID is 202.103.12.1 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 *> 10.10.1.0/24 0.0.0.0 100 32768 0 i <-/1> *> 10.10.2.0/24 202.103.12.2 0 0 0 10000 20000 10086 i <-/1> Total number of prefixes 2在 FW1 上查看路由表中的 BGP 路由,从 FW2 学习到的 EBGP 路由被正确加载。
FW1 # get router info routing-table bgp Routing table for VRF=0 B 10.10.2.0/24 [20/0] via 202.103.12.2 (recursive is directly connected, port4), 00:09:25, [1/0]同理,在 FW2 上的 EBGP 邻居中开启
allowas-in-enable,FW2 也可以正常学习到 FW1 发布的路由。不推荐使用此方法解决,会破坏 EBGP 的防环机制。