Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 => 192.168.1.0/24, eth1 => 192.168.2.0/24, eth2 => 192.168.3.0/24, eth3 => 192.168.4.0/24, each client machine with in those 4 subnets can talk to each other.

Any suggest script ?

share|improve this question
add comment

1 Answer

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 192.168.1.0/24 -d 192.168.2.0/24 -j SNAT --to 192.168.2.1
# iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -d 192.168.1.0/24 -j SNAT --to 192.168.1.1

Where 192.168.2.1 is the IP address of eth1 and the default gateway for subnet 192.168.2.0/24, 192.168.1.1 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 '192.168.2.1' Bad argument '192.168.1.1' 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 192.168.2.1 ==> j- SNAT --to 192.168.2.1, 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
show 6 more comments

Your Answer

 
discard

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.