FreeBSD的策略路由要比Linux的繁琐. 总的来说靠的是 FIB (routing table) 和 防火墙 (ipfw/pf) 包转发
以下只说实现方式, 不提原理
默认的kernel是只有1个fib.
sysctl的net.fibs只读选项, 所以如果要修改只能在/boot/loader.conf操作并且重启.
<code>net.fibs=“32”</code>
或者加在内核配置里面重新编译内核, 重启
<code>options ROUTETABLES=32</code>
以上的32代表启用32个FIB.
现代系统 net.fibs 可以动态调整了.
sysctl net.fibs=32
/sbin/route add default 10.1.1.1 -fib 1 /sbin/route add -inet6 default 2001:abcd::1 -fib 1
netstat -rn -F 1 route -n get 8.8.8.8 -fib 1
让某程序使用路由表1 (fib 1)
setfib 1 /path/program
让某个服务运行在路由表1上
# /etc/rc.conf xxx_fib="1"
防火墙的原理是
pass in quick on gre1 reply-to ( gre1 10.1.1.1 ) inet from any to gre1 pass out quick on $ext_if route-to ( gre1 10.1.1.1 ) inet from gre1 to any
指定某些IP出口使用特定路由表
pass inet from 192.168.101/24 to any rtable 1
ipfw add fwd 10.1.1.1 ip from 10.1.1.2 to any via $ext_if ipfw add setfib 1 ip from any to any via gre1
指定某些IP出口使用特定路由表
ipfw add setfib 1 ip from 192.168.101/24 to any