Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an Ubuntu 12.10 box with 2 NICs. eth0 is connected to my 192.168.1.X network, which is connected to my home router and out to the internet. I want the other interface, eth1,to support 10.0.0.x and allow devices on that network to access the internet through my ubuntu box. I do not need dhcp on the 10.0.0.x network.

Here's a schematic: Internet ---> home router ----> ubuntu[eth0:192.168.1.x, eth1:10.0.0.x] ---> [10.0.0.x device]

How do I configure the ubuntu box to share the internet with devices on that subnetwork?


share|improve this question

migrated from Jul 2 '13 at 23:29

This question came from our site for system and network administrators.


You'll need to enable forwarding in the kernel and then create a few rules in iptables.

The following short script will usually do it. You'll need to adjust the network devices accordingly. Sometimes you can get away with not including any iptables rules. If the following script doesn't do it, run "iptables -F && iptables -X" to clear things out and try again. The gateway for internal hosts should be the address for the 10.0.0.x device.

echo 1 > /proc/sys/net/ipv4/ip_forward

/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/sbin/iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

/sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
/sbin/iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
share|improve this answer

You must log in to answer this question.