黑洞路由不生效
2025/10/29大约 1 分钟
黑洞路由不生效
问题现象
通常会在 IPSec VPN 环境下配置高管理距离(distance)的黑洞路由,避免 IPSec 连接中断时,VPN 流量匹配默认路由被送到 Internet。
某用户在配置 VPN 路由对应的黑洞路由,如下所示,distance 配置为 255。
config router static edit 15 set status disable set dst 192.168.123.0 255.255.255.0 set distance 20 set device "VPN_Tunnel1" next edit 16 set dst 192.168.123.0 255.255.255.0 set distance 255 set blackhole enable set vrf 0 next end查看路由表中没有该黑洞路由,VPN 隧道中断后,流量仍然匹配默认路由从 wan1 接口转发。
FortiGate # get router info routing-table static Routing table for VRF=0 S* 0.0.0.0/0 [1/0] via 172.22.6.1, wan1, [1/0]但在路由 Database 中可以看到该黑洞路由。
FortiGate # get router info routing-table database | grep 192.168.123.0 S 192.168.123.0/24 [20/0] via VPN_Tunnel1 tunnel 10.0.0.2, [1/0] S 192.168.123.0/24 [255/0] is a summary, Null, [1/0]
问题原因
路由管理距离(distance)255 表示该路由无效。路由只能在 routing-table database 中可见。不会插入到路由转发表中,所以 VPN 流量不会按预期丢弃(路由),而是匹配默认路由从 wan1 接口转发。
解决方法
任何静态路由的管理距离都需要 ≤ 254。否则,路由条目将被视为无效路由。
config router static
edit 16
set dst 192.168.123.0 255.255.255.0
set distance 254
set blackhole enable
set vrf 0
next
end