如何configurationiptables规则来连接2 eth到networking(转发和伪装)

需要一些帮助来configurationiptables规则转发和伪装

鉴于我有这些configuration:

switch1 —-(eth1)—– router —-(eth2)—– switch2
|
|
了(eth0)
|
|
互联网

多台PC通过switch1和switch2连接

我在Ubuntu服务器上运行这个networking,我假设eth1和eth2具有相同的IP地址,因为所有连接的PC的默认网关是这个路由器的IP地址。

所以我做的是:

  • /etc/sysctl.conf并取消注释net.ipv4.ip_forward = 1
  • /etc/rc.local并为iptables添加规则,比如:

    echo 1> / proc / sys / net / ipv4 / ip_forward
    iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
    iptables -A FORWARD -i eth2 -o eth0 -j ACCEPT
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

  • 对于路由器networking的接口configuration,请转到/ etc / network / interfaces

    汽车
    iface lo inet loopback

    auto eth0
    iface eth0 inet static
    地址10.151.74.30
    networking掩码255.255.255.252
    网关10.151.74.29

    auto eth1
    iface eth1 inet static
    地址172.16.0.1
    networking掩码255.255.255.0

    auto eth2
    iface eth2 inet static
    地址172.16.0.1
    networking掩码255.255.255.0

    所以问题是所有通过eth2连接到路由器的PC都无法连接到互联网(tuntap),但是通过eth1连接的所有PC都可以连接到互联网(tuntap)。

    因此,在configurationiptables时有什么想法吗? 还是我误解了?
    帮助和build议真的很感激。 我刚开始学习互联网一个月前,所以基本上需要一个指导。 非常感谢 :)

  • 您不能有2个接口具有相同的IP地址。 此外,即使将一个接口的IP地址更改为同一networking中的另一个地址(如172.16.0.2),也不会如此。

    为什么在同一个networking中需要2个接口? 切换开关1和切换开关2互相看到还是分开?

    如果他们看到对方,那么你的configuration肯定有问题。

    如果他们不这样做,你可以在switch2上build立另一个networking,例如172.16.1.0/24,一切都会好的。

    顺便说一句:如果在/etc/sysctl.confnet.ipv4.ip_forward = 1 ,则不需要echo 1 > /proc/sys/net/ipv4/ip_forward