Preferred Source
Preferred Source
功能简介
当 FortiGate 产生本地发起(local-out)的流量时,默认会采用出接口的主 IP 作为源地址。如:
- FortiGuard 查询
- FortiGate Cloud 隧道
- DNS 查询
- BGP 对等会话
- 远程 RADIUS/LDAP 流量
- 设备自身发起的 ping、traceroute
从 FortiOS v7.4.0 及之后版本,引入了 Preferred Source 功能,可在静态路由、SD-WAN 成员或 BGP route-map 中指定 Local-out 流量应优先使用的源地址,以实现更精细的源 IP 管控。
配置方法
静态路由
在静态路由条目中使用 preferred-source,可以让匹配该路由的 Local-out 流量使用指定的源地址。
config router static
edit <id>
set dst 10.10.12.0 255.255.255.0
set gateway 10.255.2.2
set preferred-source 192.168.100.1
set device "port2"
next
endSD-WAN
在 SD-WAN 成员配置中使用 preferred-source,可让 Local-out 流量在经过该 SD-WAN 成员时使用自定义的源地址。
重要
- SD-WAN 健康检查的探测流量需要使用
set source <ip_address>,而不是preferred-source。 - SD-WAN 成员中配置的
preferred-source优先于静态路由中配置的preferred-source。
config system sdwan
config members
edit <id>
set preferred-source 192.168.100.1
next
end
endBGP Route-map
在 route-map 中可通过 set-ip-prefsrc 设置源地址,然后将该 route-map 作为 route-map-in 应用到邻居。BGP 邻居建立、BGP 邻居间通信等 Local-out 流量会采用该源地址。
config router route-map
edit "<route-map_name>"
config rule
edit <id>
set set-ip-prefsrc <ip_address>
next
end
next
end
config router bgp
config neighbor
edit 169.254.10.1
set route-map-in <route-map_name>
next
end
end注意事项
源地址优先级
如果系统其他位置(例如 config system dns)显式配置了 source-ip,则该 source-ip 会覆盖preferred-source。
相关信息
如下所示,即使路由设置了 preferred-source,DNS 查询仍会使用 192.168.100.99。
config router static
edit 1
set dst 223.5.5.5 255.255.255.255
set gateway 192.168.100.254
set preferred-source 192.168.100.1
set device "port2"
next
end
config system dns
set primary 223.5.5.5
set source-ip 192.168.100.99
end本地地址要求
FortiGate 不强制 Preferred Source 必须是本地接口 IP,但若该地址不属于设备的任一接口,则回复流量可能无法返回,最终导致流量丢失。 如果使用的源地址不是本地接口地址,可通过以下方式确保回程可达:
使用 Loopback 接口:
config system interface edit "loopback1" set ip 100.1.1.1 255.255.255.255 set type loopback next end使用 Secondary IP:
config system interface edit "port2" set secondary-IP enable config secondaryip edit <id> set ip 100.1.1.1 255.255.255.255 next end next end使用开启
arp-reply的 IP Pool:config firewall ippool edit "pool1" set startip 100.1.1.1 set endip 100.1.1.1 set arp-reply enable next end
IPsec 相关流量
IPsec 隧道协商与 ESP 流量不会使用静态路由或 SD-WAN 成员中配置的 preferred-source,而是使用:
- 已配置的 local-gw。
- 若未配置 local-gw,则使用接口主 IP。
config vpn ipsec phase1-interface
edit "example"
set interface "port2"
set local-gw 202.103.2.1
set remote-gw 101.202.1.1
next
end