我有多个使用相同的网关IP的VPN连接(我没有能力改变这一点,因为它是我的控制之外)。 这些VPN都提供对不同networking的访问,并且networking至less有一个或两个上行链路,因此在所有情况下都需要网关IP。 有了Linux,路由到networking,我可以简单地做:
ip route add $destination_1 via $gateway_ip dev $interface_1 ip route add $destination_2 via $gateway_ip dev $interface_2 ip route add $destination_3 via $gateway_ip dev $interface_3
等等
然后,Linux将把每个目标networking的stream量放到正确的接口上,然后转向正确的网关,因此每个接口的网关IP都是一样的。
我的问题是,我怎样才能在OpenBSD中实现这一点? 我试过了,失败了。 我的发现是,对于一个特定的目的地,我可以:
但我不知道如何指定两者。
使用-ifp修饰符进行路由 。 从手册页 :
In a change or add command where the destination and gateway are not sufficient to specify the route, the -ifp or -ifa modifiers may be used to determine the interface name or interface address.
所以这样的工作:
# for arg in tun0 tun1 tun2; do ifconfig $arg 192.168.11.1/24; done # route add 10/8 -iface 192.168.11.1 -ifp tun0 add net 10/8: gateway 192.168.11.1 # route add 172.16/12 -iface 192.168.11.1 -ifp tun1 add net 172.16/12: gateway 192.168.11.1 # route add 192.168.254/24 -iface 192.168.11.1 -ifp tun2 add net 192.168.254/24: gateway 192.168.11.1 # route show -inet Routing tables Internet: Destination Gateway Flags Refs Use Mtu Prio Iface 10/8 192.168.11.1 GS 0 0 - 8 tun0 localhost localhost UHl 0 22 32768 1 lo0 172.16/12 192.168.11.1 S 0 0 - 8 tun1 192.168.11.1 192.168.11.1 UHhl 1 4 - 1 tun0 [...my real routes omitted...] 192.168.254/24 192.168.11.1 S 0 0 - 8 tun2
如果您的目的地路线重叠,那么您可以使用pf和路由标签进行匹配或路由域 。