Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

If I have an 4 (or more) ethernet port linux box, How to setup it as router to handle 4 class c subnet ? for example, eth0 =>, eth1 =>, eth2 =>, eth3 =>, each client machine with in those 4 subnets can talk to each other.

Any suggest script ?

share|improve this question

Per your interfaces settings, you need to let the kernel do Network Address Translation to route packets across these subnets. Try this first:

# iptables -t nat -A POSTROUTING -s -d -j SNAT --to
# iptables -t nat -A POSTROUTING -s -d -j SNAT --to

Where is the IP address of eth1 and the default gateway for subnet, alike.

And make sure you have net.ipv4.ip_forward=1 in /etc/sysctl.conf. And run sysctl -p to make that change in effect.

share|improve this answer
Please comment if that works or not. I do not have machines to test right now at work. – fossilet Apr 5 '12 at 3:17
Bad argument '' Bad argument '' By the way, I am using Ubuntu Server 11.10 i386 3.0.0-17-generic-pae #30-Uuntu SMP Thu Mar 8 17:53:35 UTC... – Fox Mulder Apr 5 '12 at 13:57
ok, I am change the -j SNAT ==> j- SNAT --to, It's accept now. – Fox Mulder Apr 5 '12 at 14:01
Sorry, I now update my post. You can test with only one iptables rule first. – fossilet Apr 5 '12 at 14:19
Thanks your help. It's won't work if only with POSTROUTING/SNAT, But after add PREROUTING/DNAT, It's work now...... :) – Fox Mulder Apr 5 '12 at 14:45

Your Answer


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

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