I have two physical networks:

eth0 with with several PCs and NAT adresss where PPPoE connecting to inet;

eth1 with several PCs and no internet.

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static

auto eth1
iface eth1 inet static

up route add -net gw dev eth0
up route add -net gw dev eth1

and got:

Reconfiguring network interfaces...RTNETLINK answers: File exists
Failed to bring up eth1.

what route I should add and why eth1 failed? What default gateway I should add for network? Can anywone help?


You should only have 1 gateway as far as I know. All traffic goes to the Internet through that interface.

route add default gw eth0

Should be sufficient.

Although I'm not sure if it's required as you set the gateway in your eth0 config. See what the route command lists before you try adding it, it will probably have a default listed.

Then as long as you have IP forwarding and iptables enabled, all other computers can route through eth0 OK.

NAT setup in Ubuntu

If you require 2 subnets to talk to each other then you should configure iptables to allow that traffic. Omitting one of the lines of the iptables commands should prevent traffic in both directions.

First enable ip forwarding echo "1" > /proc/sys/net/ipv4/ip_forward

Then configure iptables.

sudo iptables -A FORWARD -i eth0 -o eth1 -s -d -j ACCEPT
sudo iptables -A FORWARD -i eth1 -o eth0 -s -d -j ACCEPT

To make this permanent do the following.

sudo iptables-save > /etc/iptables.ipv4.nat

add the line up iptables-restore < /etc/iptables.ipv4.nat to the bottom of /etc/network/interfaces

Then edit /etc/sysctl.conf.

net.ip4.ip_forward = 1

You can put the iptables-save file wherever is best for you.

  • Thanks for reply. Yes, the only gatway is But I don't need internet in Also PCs in 1.0/24 should not see PCs in 0.0/24. When I tried to configure network without routes I can't ping anything in That's why I think about route add. – Alexander B Feb 13 '16 at 18:32
  • Added Subnet routing to the answer. You may need to adjust the iptables commands to suit your required setup. – Sir_Scofferoff Feb 13 '16 at 18:53
  • Thanks a lot for the help. So the whole setup is enable IP forwarfing and drop other traffic between subnets later? For example, if I don't need samba (Windows Networking in my case) block some ports in iptables, right? – Alexander B Feb 13 '16 at 19:02
  • yes, there's far too much you can do with iptables to list here. Samba is best configured to not listen on eth1 if you don't want that network to use it. "interfaces = & bind interfaces only = yes" for e.g. – Sir_Scofferoff Feb 13 '16 at 19:08
  • Hmmm... Still no ping from localhost to Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination ACCEPT all -- ACCEPT all -- Chain OUTPUT (policy ACCEPT) target prot opt source destination – Alexander B Feb 13 '16 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.