Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

Thanks!

share|improve this question

migrated from serverfault.com Jul 2 '13 at 23:29

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

    

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.