BGP 路由刷新
BGP 路由刷新
功能介绍
默认的 BGP 配置下,当 BGP 邻居配置中引用的路由策略(如 route-map、distribute-list 等)修改了属性或过滤的路由条目时,BGP 路由表并不会立即更新,需要执行路由刷新来重新获取 BGP 路由,并进行路由过滤/修改。
FortiGate 路由刷新的方法有以下 3 种:
- 方法 1 - 使用 BGP route-refresh
- 方法 2 - 使用 soft-reconfiguration
- 方法 3 - 重置 BGP 邻居
网络拓扑

- FW1 与 FW2 建立 iBGP 邻居。
- 初始状态下,FW1 发布自己的路由 10.10.1.0/24、10.10.2.0/24、10.10.3.0/24 给 FW2,FW1 与 FW2 都不开启
soft-reconfiguration功能。 - 初始状态下,FW2 的 BGP 入方向引用 route-map,只允许学习 FW1 发送的路由 10.10.1.0/24、10.10.2.0/24。
配置步骤
基础网络配置(略)。
配置 FW1 的 BGP,与 FW2 建立 iBGP 邻居,并发布自己的路由 10.10.1.0/24、10.10.2.0/24、10.10.3.0/24 给 FW2。
config router bgp set as 10086 set router-id 192.168.12.1 config neighbor edit "192.168.12.2" set remote-as 10086 next end config network edit 1 set prefix 10.10.1.0 255.255.255.0 next edit 2 set prefix 10.10.2.0 255.255.255.0 next edit 3 set prefix 10.10.3.0 255.255.255.0 end end在 FW2 上配置 prefix-list,内容为 FW1 的发布的 BGP 路由 10.10.1.0/24、10.10.2.0/24。
config router prefix-list edit "Prefix_FW1" config rule edit 1 set prefix 10.10.1.0 255.255.255.0 unset ge unset le next edit 2 set prefix 10.10.2.0 255.255.255.0 unset ge unset le next end next end在 FW2 上配置 route-map,允许 Prefix
Prefix_FW1中的 BGP 路由,拒绝其他路由。config router route-map edit "RMP_from_FW1" config rule edit 1 set match-ip-address "Prefix_FW1" next edit 2 set action deny next end next end在 FW2 上配置 BGP,与 FW2 建立 iBGP 邻居,并发布自己的路由 10.10.4.0/24 给 FW2。在入方向引用步骤 4 配置的 route-map,只允许接收 FW1 发布的 BGP 路由 10.10.1.0/24、10.10.2.0/24。
config router bgp set as 10086 set router-id 192.168.12.2 config neighbor edit "192.168.12.1" set remote-as 10086 set route-map-in "RMP_from_FW1" next end config network edit 1 set prefix 10.10.4.0 255.255.255.0 next end end在 FW1 上查看 BGP 路由学习情况,可以正确学习到 FW2 宣告的路由 10.10.4.0/24。
FW1 # get router info bgp summary VRF 0 BGP router identifier 192.168.12.1, local AS number 10086 BGP table version is 2 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 192.168.12.2 4 10086 22 23 1 0 0 00:17:28 1 Total number of neighbors 1 FW1 # get router info routing-table bgp Routing table for VRF=0 B 10.10.4.0/24 [200/0] via 192.168.12.2 (recursive is directly connected, port2), 00:17:13, [1/0]在 FW1 上查看通告给 FW2 的 BGP 路由,与配置一致。
FW1 # get router info bgp neighbors 192.168.12.2 advertised-routes VRF 0 BGP table version is 6, local router ID is 192.168.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 *>i10.10.1.0/24 192.168.12.1 100 32768 0 i <-/-> *>i10.10.2.0/24 192.168.12.1 100 32768 0 i <-/-> *>i10.10.3.0/24 192.168.12.1 100 32768 0 i <-/-> Total number of prefixes 3在 FW2 上查看 BGP 路由学习情况,可以正确学习到 FW1 发布的 BGP 路由 10.10.1.0/24、10.10.2.0/24,而 10.10.3.0/24 被 route-map 过滤掉。
FW2 # get router info bgp summary VRF 0 BGP router identifier 192.168.12.2, local AS number 10086 BGP table version is 1 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 192.168.12.1 4 10086 3 4 1 0 0 00:00:30 2 Total number of neighbors 1 FW2 # get router info routing-table bgp Routing table for VRF=0 B 10.10.1.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 00:00:07, [1/0] B 10.10.2.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 00:00:07, [1/0]在 FW2 的 route-map 引用的 prefix 中增加 10.10.3.0/24 的路由,这样 route-map 就开始允许接收 10.10.3.0/24 的 BGP 路由。
config router prefix-list edit "Prefix_FW1" config rule edit 3 set prefix 10.10.3.0 255.255.255.0 unset ge unset le next end next end在 FW2 上查看学习到的 BGP 路由,仍然只有之前学习到的 BGP 路由 10.10.1.0/24、10.10.2.0/24,没有 FW1 发布的 10.10.3.0/24 路由。
FW2 # get router info routing-table bgp Routing table for VRF=0 B 10.10.1.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 02:37:10, [1/0] B 10.10.2.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 02:37:10, [1/0]如果没有任何操作,路由将一直不会更新。可以使用如下 3 种方法进行路由刷新。
路由刷新方法
方法 1 - 使用 BGP route-refresh
在 FW2 上查看在内存中保存的从 FW1 收到的 BGP 路由,由于没有开启软重配(soft-reconfiguration)功能,内存中不会保存从 FW1 收到的所有路由。
FW2 # get router info bgp neighbors 192.168.12.1 received-routes % Inbound soft reconfiguration not enabled % No prefix for neighbor 192.168.12.1确保 FW1 和 FW2 的 BGP 邻居配置中都开启了
capability-route-refresh功能(默认开启)。重要
capability-route-refresh用于手动路由刷新时向邻居发送 route-refresh 请求。该功能符合 RFC 2918,如果 BGP 邻居设备不是 FortiGate,需要也支持 RFC 2918 才行。
config router bgp edit "192.168.12.1" set capability-route-refresh enable next end end在 FW2 上使用
execute router clear bgp ip 192.168.12.1 in命令进行 BGP 邻居路由入方向的刷新,向 FW1 请求 BGP Update,并重新匹配 route-map 接收路由。等待若干秒后,再次查看 FW2 的 BGP 路由表,可以看到 10.10.3.0/24 已经入表。重要
如果 BGP 邻居配置中没有开启
soft-reconfiguration,使用execute router clear bgp ip 192.168.12.1 soft in,将会与此步命令(execute router clear bgp ip 192.168.12.1 in)执行相同的操作。FW2 # execute router clear bgp ip 192.168.12.1 in FW2 # get router info routing-table bgp Routing table for VRF=0 B 10.10.1.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 03:08:47, [1/0] B 10.10.2.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 03:08:47, [1/0] B 10.10.3.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 00:10:43, [1/0]FW2 上的 BGP Debug 信息,显示 FW2 向 FW1 发送了 NLRI(Route-Refresh)的更新请求(RFC 2918),收到 FW1 的 BGP Update 后,从中取出 10.10.1.0/24、10.10.2.0/24、10.10.3.0/24 路由条目,10.10.3.0/24 被放入路由表,10.10.1.0/24 和 10.10.2.0/24 由于路由表中已存在而忽略。
FW2 # diagnose ip router bgp level info FW2 # diagnose ip router bgp all enable FW2 # diagnose debug console time enable FW2 # diagnose debug enable 2024-04-11 14:46:27 BGP: 192.168.12.1-Outgoing [ENCODE] Route-Refresh: RR-Type New MsgSize 23 2024-04-11 14:46:27 BGP: 192.168.12.1-Outgoing [ENCODE] Msg-Hdr: Type 5 2024-04-11 14:46:27 BGP: 192.168.12.1-Outgoing [ENCODE] Route-Refresh: RR-Type New MsgSize 23 2024-04-11 14:46:27 BGP: 192.168.12.1-Outgoing [ENCODE] Msg-Hdr: Type 5 2024-04-11 14:46:33 BGP: 192.168.12.1-Outgoing [DECODE] Update: Starting UPDATE decoding... Bytes To Read (37), msg_size (37) 2024-04-11 14:46:33 BGP: 192.168.12.1-Outgoing [DECODE] Update: NLRI Len(12) 2024-04-11 14:46:33 BGP: 192.168.12.1-Outgoing [FSM] State: Established Event: 27 2024-04-11 14:46:33 BGP: 192.168.12.1-Outgoing [RIB] Update: Received Prefix 10.10.1.0/24 path_id 0 2024-04-11 14:46:33 BGP: [DAMP] bgp_rfd_rt_update(): Route State: NONE, ret=0 2024-04-11 14:46:33 BGP: 192.168.12.1-Outgoing [RIB] Update: ...duplicate route ignored 2024-04-11 14:46:33 BGP: 192.168.12.1-Outgoing [RIB] Update: Received Prefix 10.10.3.0/24 path_id 0 2024-04-11 14:46:33 BGP: VRF 0 NSM announce: 10.10.3.0/24 2024-04-11 14:46:33 BGP: 192.168.12.1-Outgoing [RIB] Update: Received Prefix 10.10.2.0/24 path_id 0 2024-04-11 14:46:33 BGP: [DAMP] bgp_rfd_rt_update(): Route State: NONE, ret=0 2024-04-11 14:46:33 BGP: 192.168.12.1-Outgoing [RIB] Update: ...duplicate route ignoredFW1 上的 BGP Debug 信息,显示 FW1 收到了 FW2 的 BGP NLRI 更新请求(Route-Refresh),并向 FW2 发送了 BGP Update。
FW1 # diagnose ip router bgp level info FW1 # diagnose ip router bgp all enable FW1 # diagnose debug console time enable FW1 # diagnose debug enable 2024-04-11 14:46:27 BGP: 192.168.12.2-Outgoing [FSM] State: Established Event: 29 2024-04-11 14:46:27 BGP: 192.168.12.2-Outgoing [DECODE] Msg-Hdr: type 5, length 23 2024-04-11 14:46:27 BGP: 192.168.12.2-Outgoing [DECODE] R-Refresh: AFI/SAFI (1/1) 2024-04-11 14:46:27 BGP: 192.168.12.2-Outgoing [DECODE] PEER_STATUS_ORF_NOT_WAIT_REFRESH set! 2024-04-11 14:46:33 BGP: 192.168.12.2-Outgoing [ENCODE] Msg-Hdr: Type 2 2024-04-11 14:46:33 BGP: 192.168.12.2-Outgoing [ENCODE] Attr IP-Unicast: Tot-attr-len 21 2024-04-11 14:46:33 BGP: 192.168.12.2-Outgoing [ENCODE] Update: Msg #9 Size 56FW2 发出的 BGP Route-Rfresh 请求报文的格式如下。

FW1 返回的 BGP Update 报文如下,包含自己宣告的 3 条路由,抓包文件请参考 bgp_route_refresh.pcap。
重要
由于未开启
soft-reconfiguration,邻居发布的全量路由不会保存在内存表中。所以使用capability-route-refresh功能请求对端更新路由,并不会马上得到对端的更新响应,会由对端配置的advertisement-interval(FortiGate 默认 30s)决定。
FW2 上查看 BGP capability-route-refresh 功能的开启状态,如下所示,在 BGP 邻居配置中开启 capability-route-refresh 的状态下,FW2 即有 Route refresh 的通告功能,也有 Route refresh 的接受功能。
FW2 # get router info bgp neighbors 192.168.12.1 | grep refresh Route refresh: advertised and received (old and new) Route refresh request: received 0, sent 0期间相关 BGP 邻居不会中断,路由表中原有的 BGP 路由没有消失。
方法 2 - 使用 soft-reconfiguration
在 FW2 上的 BGP 中开启
soft-reconfiguration功能(对于 BGP IPv6 路由,该功能为soft-reconfiguration6)。config router bgp config neighbor edit "192.168.12.1" set soft-reconfiguration enable next end end在 FW2 上查看在内存中保存的从 FW1 收到的 BGP 路由,由于开启了软重配(soft-reconfiguration)功能,内存中会保存从 FW1 收到的所有 BGP 路由(被 route-map 过滤前的路由)。
FW2 # get router info bgp neighbors 192.168.12.1 received-routes VRF 0 BGP table version is 2, local router ID is 192.168.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 *>i10.10.1.0/24 192.168.12.1 100 0 0 i <-/-> *>i10.10.2.0/24 192.168.12.1 100 0 0 i <-/-> *>i10.10.3.0/24 192.168.12.1 100 0 0 i <-/-> Total number of prefixes 3在 FW2 上使用
execute router clear bgp ip 192.168.12.1 soft in命令进行 BGP 邻居路由入方向的刷新,不需要向 FW1 请求 BGP Update,直接从内存中保存的 BGP 路由遍历,并重新匹配 route-map 接收路由。再次查看 FW2 的 BGP 路由表,可以看到 10.10.3.0/24 直接入表(不需要像“方法 1 - 使用 BGP route-refresh”等待若干秒)。FW2 # execute router clear bgp ip 192.168.12.1 soft in FW2 # get router info routing-table bgp Routing table for VRF=0 B 10.10.1.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 00:08:26, [1/0] B 10.10.2.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 00:08:26, [1/0] B 10.10.3.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 00:03:02, [1/0]FW2 上的 BGP Debug 信息,显示 BGP 从内存中读取从 FW1 收到的所有 BGP 路由,从中取出 10.10.1.0/24、10.10.2.0/24、10.10.3.0/24 路由条目,10.10.3.0/24 被放入路由表,10.10.1.0/24 和 10.10.2.0/24 由于路由表中已存在而忽略。
重要
不需要向 FW1 发送 BGP Route-Refresh 请求报文。
FW2 # diagnose ip router bgp level info FW2 # diagnose ip router bgp all enable FW2 # diagnose debug console time enable FW2 # diagnose debug enable 2024-04-11 17:22:54 BGP: [RIB] Scanning BGP RIB for VRF 0... 2024-04-11 17:22:54 BGP: [NSM] Verified NH 192.168.12.1 with NSM 2024-04-11 17:22:58 BGP: 192.168.12.1-Outgoing [RIB] Update: Received Prefix 10.10.1.0/24 path_id 0 2024-04-11 17:22:58 BGP: [DAMP] bgp_rfd_rt_update(): Route State: NONE, ret=0 2024-04-11 17:22:58 BGP: 192.168.12.1-Outgoing [RIB] Update: ...duplicate route ignored 2024-04-11 17:22:58 BGP: 192.168.12.1-Outgoing [RIB] Update: Received Prefix 10.10.2.0/24 path_id 0 2024-04-11 17:22:58 BGP: [DAMP] bgp_rfd_rt_update(): Route State: NONE, ret=0 2024-04-11 17:22:58 BGP: 192.168.12.1-Outgoing [RIB] Update: ...duplicate route ignored 2024-04-11 17:22:58 BGP: 192.168.12.1-Outgoing [RIB] Update: Received Prefix 10.10.3.0/24 path_id 0 2024-04-11 17:22:58 BGP: VRF 0 NSM announce: 10.10.3.0/24期间相关 BGP 邻居不会中断,路由表中原有的 BGP 路由没有消失。
方法 3 - 重置 BGP 邻居
在 FW2 上使用
execute router clear bgp ip 192.168.12.1命令进行 BGP 邻居重置,重新建立与 FW1 的 BGP 邻居并学习 BGP 路由。重要
不推荐使用此方法,BGP 邻居需要重新建立,流量中断时间长。
使用 execute router clear bgp all 可以重置所有的 BGP 邻居,请谨慎使用。
FW2 # execute router clear bgp ip 192.168.12.1随后 FW2 与 FW1 的 BGP 邻居被重置,并重新建立 BGP 邻居。
FW2 # get router info bgp summary VRF 0 BGP router identifier 192.168.12.2, local AS number 10086 BGP table version is 2 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 192.168.12.1 4 10086 17 20 0 0 0 never Idle Total number of neighbors 1等待 BGP 邻居建立完成并重新学习 BGP 路由后,10.10.3.0/24 被放入路由表。
FW2 # get router info bgp summary VRF 0 BGP router identifier 192.168.12.2, local AS number 10086 BGP table version is 2 1 BGP AS-PATH entries 0 BGP community entries Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 192.168.12.1 4 10086 30 33 2 0 0 00:09:03 3 Total number of neighbors 1 FW2 # get router info routing-table bgp Routing table for VRF=0 B 10.10.1.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 00:08:45, [1/0] B 10.10.2.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 00:08:45, [1/0] B 10.10.3.0/24 [200/0] via 192.168.12.1 (recursive is directly connected, port2), 00:08:45, [1/0]FW2 上的 BGP Debug 信息,显示 FW2 主动重置了 BGP 邻居,并通知了 FW1。
重要
不需要向 FW1 发送 BGP Route-Refresh 请求报文。
FW2 # diagnose ip router bgp level info FW2 # diagnose ip router bgp all enable FW2 # diagnose debug console time enable FW2 # diagnose debug enable 2024-04-11 17:28:23 id=20300 msg="BGP: %BGP-5-ADJCHANGE: VRF 0 neighbor 192.168.12.1 Down BGP Notification CEASE" 2024-04-11 17:28:23 id=20300 msg="BGP: %BGP-5-ADJCHANGE: VRF 0 neighbor 192.168.12.1 Down User reset"期间相关 BGP 中断,路由表中原有的 BGP 路由消失。
总结
- 三种刷新路由的方法优缺点总结:
- 方法 1 - 使用 BGP route-refresh:
- 优点:BGP 邻居和已有路由不会中断,相比方法 2,不需要在本地内存中保存未经路由策略过滤/修改的路由,节省内存。
- 缺点:需要 BGP 邻居设备厂商支持 RFC 2918(FortiGate 支持);根据对端配置的
advertisement-interval,收到更新报文存在一定延迟。 - 配合
exe router clear bgp ip 192.168.12.2 in使用。
- 方法 2 - 使用 soft-reconfiguration**(推荐)**:
- 优点:BGP 邻居和已有路由不会中断,不需要向 BGP 邻居发送 Refresh-Route 请求,仅本地执行。
- 缺点:针对每个已建立的 BGP 邻居需要在内存中保存一份未经路由策略过滤/修改的路由列表,内存消耗较方法 1 稍大。
- 配合
exe router clear bgp ip 192.168.12.2 soft in使用。
- 方法 3 - 重置 BGP 邻居:
- 优点:不需要 BGP 邻居设备的任何 RFC 支持,所有厂商原生支持。
- 缺点:BGP 邻居会重新建立并通告路由,流量中断时间长。
- 配合
exe router clear bgp ip 192.168.12.2 all或exe router clear bgp all使用。
- 方法 1 - 使用 BGP route-refresh:
- FortiGate 不支持路由过滤/修改条件更改后的 BGP 路由条目自动更新,必须使用上述三种方法手动刷新路由。
- 对于 out 方向的路由策略(路由过滤/修改),使用
exe router clear bgp ip 192.168.12.2 out和exe router clear bgp ip 192.168.12.2 soft out都可以触发 out 方向的路由更新,从而向邻居发送 BGP Update 更新报文,本文就不再赘述。