我试图操作2个子网, 192.168.0.0/24范围内的第一个子网可以自由访问任何东西,包括第二个子网上的机器。 10.0.0.0/24范围内的第二个子网仅限于能够访问外部世界。 我不希望具有10.0.0.0/24以内的源的机器能够访问192.168.0.0/24范围内的机器,但我确实希望它能够出去。
最重要的是,在192.168.0.0/24范围内,我也想要2个网关,第一个是通过VPN路由stream量的默认网关(目前是Ubuntu VM的forms),其地址是192.168.0.250 ,第二个网关(这是面向互联网的TP-Link无线路由器)在192.168.0.1 (也是192.168.0.0/24范围的DHCP和DNS服务器)
我也有第三个网关桥接两个子网,另一个有2个NICS的Ubuntu VM,第一个是192.168.0.251 ,第二个是10.0.0.1
现在我已经解释了我想要的networking,这是我的设置和我正在经历的:
Ubuntu虚拟机192.168.0.250
192.168.0.250上的路由表如下所示:
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 10.8.0.1 128.0.0.0 UG 0 0 0 tun0 default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 10.0.0.0 192.168.0.251 255.255.255.0 UG 0 0 0 eth0 10.8.0.0 * 255.255.0.0 U 0 0 0 tun0 128.0.0.0 10.8.0.1 128.0.0.0 UG 0 0 0 tun0 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 . 192.168.0.1 255.255.255.255 UGH 0 0 0 eth0
我通过添加路线
ip rule add from 192.168.0.0/24 table default ip route add 10.0.0.0/24 via 192.168.0.251 ip rule add from 10.0.0.0/24 table sandboxgateway ip route add default via 192.168.0.1 dev eth0 table sandboxgateway
如果我删除两个sandboxgateway线,我可以访问10.0.0.1但10.0.0.X范围内的任何东西都通过VPN访问互联网,这不是我想要的。 它的iptable看起来像这样:
Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
Ubuntu虚拟机在192.168.0.251/10.0.0.1
192.168.0.251(eth0)/10.0.0.1(eth1)上的路由表如下所示:
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.0.1 255.255.255.255 UGH 0 0 0 eth0 default 192.168.0.250 0.0.0.0 UG 0 0 0 eth0 10.0.0.0 * 255.255.255.0 U 0 0 0 eth1 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
它的iptable看起来像这样:
Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination DROP all -- 10.0.0.0/24 192.168.0.0/24 Chain OUTPUT (policy ACCEPT) target prot opt source destination
问题
我遇到的问题是,虽然我的机器在192.168.0.2可以通过192.168.0.1或192.168.0.250作为其网关访问外部世界,我的机器在10.0.0.10可以访问外部世界,而无需访问192.168.0.X任何东西192.168.0.X ,我的机器在192.168.0.2不能访问10.0.0.1或10.0.0.10 ,并从Windows命令提示符tracert结果
跟踪路线到10.0.0.1最多30跳
1 <1 ms <1 ms <1 ms 192.168.0.250 2 * * * Request timed out. 3 * * * Request timed out.
为什么192.168.0.250不能路由到192.168.0.251 ?
道歉,如果我已经包含太多或太less的信息,请询问是否需要任何额外的细节来回答这个问题。
iptables packetfilter将10.0.0.0/8 ips的响应丢弃到192.168.0.0/8 IP。 在DROP规则之前添加一条规则,允许已经build立的10.0到192.168的数据包:
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
这应该够了吧。 如果没有,删除DROP规则来检查这是否真的是问题的根源。 如果是这样,你可能不得不build立一个更复杂的规则集。