Take the 2-minute tour ×

need some help on configuring iptables rule for forwarding and masquerading

Given I have these configuration:

switch1 ---- (eth1) ----- router ---- (eth2) ----- switch2

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 :

    iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
    iptables -A FORWARD -i eth2 -o eth0 -j ACCEPT

  • 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

    auto eth1
    iface eth1 inet static

    auto eth2
    iface eth2 inet static

    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 :)

  • share|improve this question
    eth1 and eth2 have the same ip? –  Laurentiu Roescu Apr 15 '13 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 '13 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 '13 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 '13 at 8:26

    1 Answer 1

    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

    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., 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.

    share|improve this answer

    Your Answer


