howto start with gateway / router / masquerading

Thread Tools Search this Thread
Special Forums IP Networking howto start with gateway / router / masquerading
# 1  
Old 08-03-2009
Question howto start with gateway / router / masquerading

Hi there,

I have only basic knowledge in Unix but I'm eager to learn.
I have a new complex (for me) exercice and I have no idea how to start.
I have a regular network on witch I'm trying to plug another network.

Here is an image of the physical network.
  • On the left is the original, three-node, standard, home network ( / An internet box (, my computer ( and a server (cassiopeia
  • I've added two ethernet adapters to cassiopeia.
    • One belongs to the top right network ( / a four-node network with cassiopeia ( and 3 machines (
    • The second belongs to the bottom right network ( / a two-node network that could host more machines but I'm laking a switch.
All three networks work fine and all machines within the same network can communicate.

What I need is to set cassiopeia (a GNU/Linux Debian) to enable communication between networks:
  • Set cassiopeia as gateway to the internet for
  • Set cassiopeia as gateway to the internet for
  • Set cassiopeia as a link between the two 172.16 networks
Let me give more specific needs:
  • When requests something like, it stays in the top right network
  • When requests something like, it's routed to the bottom right network
  • When requests something like Google, it's routed to the internet box
  • When requests something like, it's routed to the top right network
  • When requests something like Google, it's routed to the internet box
So far, I have set machines like this:
  • address =
    netmask =
    gateway =
  • address =
    netmask =
    gateway =
Now comes my question:
What should I install on cassiopeia (GNU/Linux Debian) to serve my needs? Is is a gateway, a router or what? Do you know free softwares? Do you know man pages to help me configure it?

Thanks for your help.
# 2  
Old 08-04-2009
Since it's all private IP addresses, simple IP forwarding should be enough. In /etc/sysctl.conf, set net.ipv4.ip_forward = 1 , and to enable it right away, type
echo 1 > /proc/sys/net/ipv4/ip_forward

as root
# 3  
Old 08-04-2009
Thanks pludi.
Your answer looked great ! But it doesn't work.
So far I found out that there might be no software to install.
Just activate ip_forwarding (as you said) and set some iptables.
This second part seems to be the most important and I have no idea how it works.
However, I found a manual that looks pretty well documented here.
If anyone has any advice, I'd be very happy.
# 4  
Old 08-04-2009
Seems like iptables are required. Shame on me for not noticing earlier.

For iptables, there's a pretty good tutorial here, with an example script for a DMZ that could be adapted.

Since the iptables rules and chain traversal aren't really intuitive, might I suggest using fwbuilder (or something similar)
# 5  
Old 08-05-2009
Hi pludi,

The configuration of iptables is extremely simple.
iptables -t nat -A POSTROUTING -j MASQUERADE

It actually means that any packet coming from any interface and going to any other one will be masqueraded.

First I have no idea what masqueraded means but I assume it is something like modifying the packet so that it's in conformity with the new network it is sent through.

Second, I understand that this means no limitation, no control and no secutity at all in the network traffic but as you said, it's all local networks and the internet box is (hopefully) doing a proper job.

Thanks for your advices anyway
# 6  
Old 08-06-2009

Masquerading is a form of network address translation (NAT). Outside of iptables, masquerading is also commonly called port address translation (PAT). Any packet which leaves a particular interface of the router will have its IP header modified to use the source IP address of the exit interfaced used on the router. Try looking up PAT on wikipedia for a good description.

With your configuration of iptables, any packet leaving any interface on the router should take on the address of the interface which it left. I would think hosts on both of the 172 networks would have problems with reply traffic from hosts on different networks, and nodes on the 192 network would not be able to access hosts on the 172 network but would be able to reach the Internet.

As an example, suppose a PC on the network pings the PC on the 192 network.

When the packet hits the router and is routed to the 192 network, the packet is NATed, and its source IP address changes to The PC on the 192 network gets the ping, and replies to it normally (with a destination IP address of

The router forwards the packet back to the ping originator on the 172 network, but masquerades the source IP address to as it sends it out that interface. The PC on the 172 network is waiting for a reply from -- getting an echo reply from would sound like bogus traffic. Thus, it never receives a reply from the 192 node and you get an error message.

Unless my thinking is fuzzy or iptables is doing something else behind the scenes, it would sound like you only want to masquerade for traffic going out of the 192 interface of the router. Try it out and see if it works as it is. If not, you can tell iptables to only masquerade for traffic leaving the 192 interface by using the '-o <INTERFACE NAME>' option within the iptables command string you posted earlier.
# 7  
Old 08-11-2009
Second, I understand that this means no limitation, no control and no secutity at all in the network traffic

Oh yeah, netfilter/iptables means packets limitation, traffic control and high security for the network.

The only device that is able to interconnect two logical networks is a router, so you want to interconnect three networks, then what you need is a router.

With iptables you can easily set up a router/firewall device for your network. It's included with Linux, so you don't have to pay or download anything at all.

What i understand of your needs is to set cassiopeia host to do something like this:

So, if i'm right you'll need three network interfaces and the problem is solved, here is how you must set iptables to make this work:

echo 1 >/proc/sys/net/ipv4/ip_forward
echo 0 >/proc/sys/net/ipv4/conf/all/send_redirecs
iptables -t nat -F
iptables -F
iptables -X
iptables -Z
iptables -A INPUT ACCEPT
iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -s -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -s -o eth2 -j MASQUERADE

I think this should work,
best regards
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Howto auto boot SPARC | How to auto supply "start /SYS" and "start /SP/console" commands

When I power ON my T4-1, I got a prompt -> where I have to start /SYS and start /SP/console. How can I auto supply these two commands ? (3 Replies)
Discussion started by: z_haseeb
3 Replies

2. UNIX for Beginners Questions & Answers

Inconsistency between RedHat 6.5 global gateway and single gateway leads to loss of default gateway

Dear friends I use RedHat 6.5, which sets the gateway in the configuration file / etc / sysconfig / network as GATEWAY =, and the gateway in the configuration file / etc / sysconfig / network-scripts / ifcfg-eth11 as GATEWAY = The two gateways are different.... (6 Replies)
Discussion started by: tanpeng
6 Replies

3. Linux

GNUGK-How to setup static gateway to gateway routing

Dear Sir I am a newbie in the world of IP telephony. I have been working with Asterisk PBX (SIP) and Cisco Call Manager (MGCP) but now I am learning on how to work GNUGK for H.323 Gatekeeper. I am having a problem, configuring static call routing on GNUGK in the section ... (0 Replies)
Discussion started by: mfondoum
0 Replies

4. UNIX for Dummies Questions & Answers

Remote Unix printing to my WinXP works with no router. How can I make it work through my router?

I set up remote printing on a clients Unix server to my Windows XP USB printer. My USB printer is connected directly to my PC (no print server and no network input on printer). With my Win XP PC connected to my cable modem (without the router), i can do lp -dhp842c /etc/hosts and it prints. I... (7 Replies)
Discussion started by: jmhohne
7 Replies
Login or Register to Ask a Question