BGP 路由汇总
BGP 路由汇总
功能简介
BGP 路由汇总(Aggregation)用于将多条更明细的 BGP 路由合并为一条汇总路由,再通告给 BGP 邻居。常见用途包括减少对外发布的前缀数量、隐藏内部明细网段,以及让上游只接收一个更粗粒度的路由条目。
在 FortiGate 上,可在 config router bgp 下通过 config aggregate-address 配置 IPv4 汇总路由。该功能适用于 FortiGate 或运行在 NAT 模式的 VDOM。
重要
汇总路由只有在至少一条更明细路由已经进入 BGP RIB 时才会被生成并通告给邻居。明细路由可以通过 config network 注入,也可以通过 connected、static、RIP、OSPF 等重发布进入 BGP。
网络需求
FortiGate 与 ISP 边界路由器建立 eBGP 邻居:
- FortiGate 本地 AS:
65020 - ISP 邻居地址:
192.0.2.1 - ISP 邻居 AS:
65000 - FortiGate 本地 Router ID:
192.0.2.2
FortiGate 内部存在以下明细网段:
10.240.0.0/2310.240.2.0/2310.240.4.0/23
对 ISP 侧只发布汇总路由 10.240.0.0/16,不再发布上述明细路由。
相关信息
示例中的 10.240.0.0/16 覆盖范围大于当前 3 条明细路由。生产环境中应确认汇总范围确实由本端负责,否则上游可能把汇总范围内但本端并未实际拥有的流量也转发到 FortiGate。
配置步骤
配置 BGP 邻居和汇总路由,其中
summary-only enable表示只通告汇总路由,不向邻居通告被汇总的明细路由。config router bgp set as 65020 set router-id 192.0.2.2 config neighbor edit "192.0.2.1" set remote-as 65000 next end config aggregate-address edit 1 set prefix 10.240.0.0 255.255.0.0 set summary-only enable next end end将明细路由注入 BGP RIB,如果明细网段在 FortiGate 路由表中已经存在,可使用
config network发布指定网段:config router bgp config network edit 1 set prefix 10.240.0.0 255.255.254.0 next edit 2 set prefix 10.240.2.0 255.255.254.0 next edit 3 set prefix 10.240.4.0 255.255.254.0 next end end提示
如果这些路由来自直连、静态或其他动态路由协议,也可以通过重发布注入 BGP。以下仅以 connected 为例,生产环境中建议配合 route-map 或 prefix-list 控制范围,避免把不需要对外发布的路由也注入 BGP。
config router bgp config redistribute "connected" set status enable end end如需同时通告汇总路由和明细路由,可关闭
summary-only。config router bgp config aggregate-address edit 1 set summary-only disable next end end
结果验证
在 FortiGate 上验证
查看路由表,可以看到 FortiGate 为汇总路由生成了一条指向
Null的 BGP summary 路由,用于避免汇总范围内未知明细前缀产生路由环路。FGT # get router info routing-table all B 10.240.0.0/16 [20/0] is a summary, Null C 10.240.0.0/23 is directly connected, port3 C 10.240.2.0/23 is directly connected, port5 C 10.240.4.0/23 is directly connected, port6查看 BGP 路由表,可以看到汇总路由为最佳路由,明细路由前面的
s表示被summary-only抑制,不会继续对外通告。FGT # get router info bgp network Network Next Hop Metric LocPrf Weight Path *> 10.240.0.0/16 0.0.0.0 32768 i s> 10.240.0.0/23 0.0.0.0 100 32768 i s> 10.240.2.0/23 0.0.0.0 100 32768 i s> 10.240.4.0/23 0.0.0.0 100 32768 i相关信息
如果
summary-only设置为disable,这些明细路由不会再显示为ssuppressed 状态,并会与汇总路由一起发布给邻居。如需确认对指定邻居的实际通告结果,可查看 advertised-routes。
get router info bgp neighbors 192.0.2.1 advertised-routes
在 ISP 邻居上验证
查看 ISP 侧 BGP 路由表,应能看到从 FortiGate 学到的
10.240.0.0/16汇总路由。FGT_ISP # get router info bgp network Network Next Hop Metric LocPrf Weight Path *> 10.240.0.0/16 192.0.2.2 0 0 0 65020 i查看 ISP 侧路由表,应能看到该汇总路由已经被安装到路由表中,下一跳为 FortiGate。
FGT_ISP # get router info routing-table all B 10.240.0.0/16 [20/0] via 192.0.2.2, port6
使用黑洞路由发布汇总前缀
除 config aggregate-address 外,也可以创建一条静态黑洞汇总路由,并将该静态路由重发布到 BGP。该方法适用于需要直接控制汇总前缀、但路由表中没有完全相同前缀的场景。
默认情况下,config network 中声明的前缀必须精确存在于本地 RIB,BGP 才会发布该前缀。虽然关闭 network-import-check 后可以绕过这项检查,但静态黑洞路由能同时提供精确的 RIB 条目,并在汇总范围内的明细路由缺失时终止流量,避免流量被递归转发或形成环路。
相关信息
以下配置是前文 aggregate-address 方式的独立替代方案,仅沿用相同的地址规划和 BGP 邻居。不要保留相同前缀的 aggregate-address 配置;如果继续通过 config network 发布明细路由,还需使用出方向过滤策略,否则明细路由会与黑洞汇总路由一起通告。
配置步骤
创建
10.240.0.0/16静态黑洞路由。将管理距离设置为254,使其仅作为汇总前缀的兜底路由。config router static edit 100 set dst 10.240.0.0 255.255.0.0 set distance 254 set blackhole enable next end创建 prefix-list,仅精确匹配该汇总前缀。未配置
ge和le时,不会匹配其下更明细的前缀。config router prefix-list edit "blackhole_summary" config rule edit 1 set prefix 10.240.0.0 255.255.0.0 unset ge unset le next end next end创建 route-map,并引用该 prefix-list。
config router route-map edit "BGP_BLACKHOLE_SUMMARY" config rule edit 1 set match-ip-address "blackhole_summary" next end next end将匹配 route-map 的静态路由重发布到 BGP。
config router bgp config redistribute "static" set status enable set route-map "BGP_BLACKHOLE_SUMMARY" end end重要
一个路由协议类型只能配置一组重发布策略。如果设备已经重发布 static 路由,应将现有匹配条件与汇总前缀合并到同一个 route-map 中,避免覆盖原有发布范围。
结果验证
查看路由表,应能看到管理距离为
254、指向Null的静态汇总路由;其下的明细路由继续按照最长前缀匹配优先转发。FGT # get router info routing-table all S 10.240.0.0/16 [254/0] is a summary, Null C 10.240.0.0/23 is directly connected, port3 C 10.240.2.0/23 is directly connected, port5 C 10.240.4.0/23 is directly connected, port6查看 BGP RIB,应能看到重发布的
10.240.0.0/16路由。通过 redistribute 注入的路由,其 Origin 通常显示为?(incomplete)。FGT # get router info bgp network Network Next Hop Metric LocPrf Weight Path *> 10.240.0.0/16 0.0.0.0 32768 ?查看对 ISP 邻居的实际通告结果,应只出现 route-map 允许的汇总前缀。
get router info bgp neighbors 192.0.2.1 advertised-routes
提示
静态黑洞路由方式是 aggregate-address 的替代方案,同一汇总前缀通常只选择其中一种方式。若同时配置,可能在 BGP RIB 中产生来源不同的相同前缀,增加选路和排查复杂度。
注意事项
config aggregate-address不会凭空生成可通告的汇总路由,至少需要一条匹配该汇总范围的明细路由已经进入 BGP RIB。summary-only enable会抑制明细路由,仅对外发布汇总路由;如果邻居仍需要明细路由,应改为summary-only disable。- 汇总路由会扩大对外可达范围。若汇总范围内存在本端未承载的子网,流量可能被上游吸引到 FortiGate 后被本端丢弃。
- 变更汇总策略后,建议检查本端
get router info bgp network、邻居advertised-routes,以及对端 BGP/RIB 是否与预期一致。 - 使用静态黑洞路由重发布汇总前缀时,应通过 route-map 做精确过滤,避免将其他静态路由意外发布到 BGP。