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.

I want to make "Ubuntu 11.10" act as a router.

I have two LAN interfaces.

Let's say interface A' IP is 172.16.1.10 ;
interface B's IP is 192.168.1.10.

How can I configure Ubuntu so that 172.16.1.1 can connect to 192.168.1.1?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Sounds as if you are configuring a router.

You only need to make a few changes to enable IP forwarding

Enable IP forwarding

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

Configure iptables

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

See also Ubuntu Wiki router

You will likely want to learn a little about iptables

Linux Firewalls Using IPTables

If all that seems a bit overwhelming, may I suggest you consider one of the linux distributions that are built to act as a router ? I like smoothwall, but there are others to choose from.

smoothwall

Firewall specific distros will handle most or all of the configuration for you and most come with a web based interface to make it ever easier.

share|improve this answer
    
It work like a magic. Now packet from 172.16.2.100 (eth0) go through 192.168.1.1 (eth1) , however packet from 192.168.1.1 cannot reach 172.16.2.100. Are there any symmetric configuration that packet can reach to both side. I try to configure iptalbes with reverse configuration, but still didn't work. Thank you. –  Isara Rungvitayakul Jan 14 '12 at 2:10
    
Can you be more specific on what you want ? Sounds as if you need to configure iptables. –  bodhi.zazen Jan 14 '12 at 5:17
    
Right now, the 172.16.1.1 one can ping to router (the real router not Ubuntu 192.168.1.1) but that router can't ping to the 172.168.1.1 Imagine that I have 2 computer (A, B) and a router (C) –  Isara Rungvitayakul Jan 14 '12 at 8:33
    
Right now, the 172.16.1.1 one can ping to router (the real router not Ubuntu 192.168.1.1) but that router can't ping to the 172.168.1.1 Imagine that I have 2 computer (A, B) and a router (C) A has IP 172.16.1.1 B has IP 192.168.1.10, and 172.16.1.10 C has IP 192.168.1.1 A connect to B B connect to C A can talk (ping) to C via B but C can't talk(ping) to A via B << my problem A can talk to C due to your solution So, what should I do next to make C can talk to A (Reverse configuration?) –  Isara Rungvitayakul Jan 14 '12 at 8:38
    
You will need a similar configuration. You really need to read an understand iptables if you are going to configure your router. You need to understand what those 3 rules I gave you perform. If you are going to allow all traffic in an out, then what is the point of configuring a router / subnet ? The answer to that question will configure iptables. –  bodhi.zazen Jan 14 '12 at 15:16

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.