2

need some help on configuring iptables rule for forwarding and masquerading

Given I have these configuration:

switch1 ---- (eth1) ----- router ---- (eth2) ----- switch2
                                             |
                                             |
                                         (eth0)
                                             |
                                             |
                                      internet

where multiple PCs are connected though switch1 and switch2 as well

i'm running this network on a Ubuntu Server where I assume eth1 and eth2 have the same IP address since the default gateway for all the connected PCs is the IP address of this router.

so what i did are :

  • go to /etc/sysctl.conf and uncomment the net.ipv4.ip_forward = 1
  • go to /etc/rc.local and add rules for iptables such as :

    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


  • and for the router network's interfaces configuration, go to /etc/network/interfaces

    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet static
    address 10.151.74.30
    netmask 255.255.255.252
    gateway 10.151.74.29

    auto eth1
    iface eth1 inet static
    address 172.16.0.1
    netmask 255.255.255.0

    auto eth2
    iface eth2 inet static
    address 172.16.0.1
    netmask 255.255.255.0

    So the problem is that all the PCs connected to the router through eth2 can't connect to the internet (tuntap) but all the PCs connected trough the eth1 can do.

    Thus, is there anything I miss on configuring the iptables? Or did I misunderstood?
    Help and suggestions are really appreciated. I just started on learning comp networking a month ago, so basically need a guidance here. Thanks a lot :)

  • 4
    • eth1 and eth2 have the same ip? Apr 15, 2013 at 7:48
    • yes they have the same ip. if the default gateway for the connected PCs is supposed to be the router's ip, but it has 2 interfaces. aren't they supposed to have the same ip?
      – AjPrames
      Apr 15, 2013 at 8:06
    • No. You should assign any IP only to one interface. What is the output of ip a ls and ip r ls ?
      – etagenklo
      Apr 15, 2013 at 8:10
    • this is the result for ip a ls : bit.ly/YID21W and ip r ls : bit.ly/ZVquih so i assumed its a wrong configuration?
      – AjPrames
      Apr 15, 2013 at 8:26

    1 Answer 1

    0

    You can not have 2 interfaces with the same IP address. Moreover it will not work like that even if you change one interface's IP address to another address in the same network (say 172.16.0.2).

    Why do you need 2 interfaces in same network? Do switches switch1 and switch2 see each other or are they separated?

    If they see each other then there is definitely something wrong with your configuration.

    If they don't, you can set up another network on switch2, e.g. 172.16.1.0/24, and everything should be fine.

    BTW: You don't need echo 1 > /proc/sys/net/ipv4/ip_forward if you have net.ipv4.ip_forward = 1 in /etc/sysctl.conf.

    You must log in to answer this question.

    Not the answer you're looking for? Browse other questions tagged .