0

I have two physical networks:

eth0 192.168.0.0/24 with with several PCs and NAT adresss 192.168.0.1 where PPPoE connecting to inet;

eth1 192.168.0.1/24 with several PCs and no internet.

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.0.2
gateway 192.168.0.1
netmask 255.255.255.0

auto eth1
iface eth1 inet static
address 192.168.1.2
netmask 255.255.255.0

up route add -net 192.168.0.0/24 gw 192.168.0.1 dev eth0
up route add -net 192.168.1.0/24 gw 192.168.1.2 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 192.168.1.0/24 network? Can anywone help?

1 Answers1

0

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

route add default gw 192.168.0.1 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 192.168.1.0/24 -d 192.168.0.0/24 -j ACCEPT
sudo iptables -A FORWARD -i eth1 -o eth0 -s 192.168.0.0/24 -d 192.168.1.0/24 -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.