使用2个networking接口configuration路由表

我有一个Linux服务器有两个networking接口: eth0 (使用公共IP地址ABC208连接到互联网)和eth1 (不连接任何东西,绑定到私人IP地址10.UV159 )。 私人networking部分是必需的,因为我configuration了VPN(OpenSwan)的configuration需要它。

我的OpenSwan VPN将我的10.UV*专用networking连接到远程10.XY*专用networking。 VPN链路build立并正常工作。

但是,当我ping远程10.XY*networking上的服务器,我需要强制源接口到eth1使其工作:

 $ ping -I eth1 10.XY31 PING 10.XY31 (10.XY31) from 10.UV159 eth1: 56(84) bytes of data. 64 bytes from 10.XY31: icmp_seq=1 ttl=60 time=29.0 ms ... 

否则,OpenSwan / VPN将不会重新路由该ping。

如何configuration我的服务器在访问任何10.XY*地址时自动将源地址设置为eth1/10.UV159 我应该添加一条路线吗? 我不想干涉VPN自己的路由机制…

我的路由表:

 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default ABC254 0.0.0.0 UG 0 0 0 eth0 10.UV0 * 255.255.255.0 U 0 0 0 eth1 ABC0 * 255.255.255.0 U 0 0 0 eth0 

10.XY31在您的路由表中不存在。 所以使用默认路由,数据包由eth0发送。 如果你想通过eth1发送它,你将需要有下一个网关,你可以使用route add -net 10.XY0 netmask 255.255.255.0 gw 10.UV159命令

这可能是一个掩码的问题,10.0.0.0networking通常在/ 8。