Tuesday, March 11, 2008

A Quick guide to set up a Linux Gateway

This document helps you to set up a small Linux based gateway as quick as possible.

run the following commands on the gateway machine:

switch into root user

1: user$ sudo -i  

Enable packet forwarding by kernel

2: root$ echo 1 > /proc/sys/net/ipv4/ip_forward   

exit root user

3: root$ exit

append the forwarding rule:

4: user$ iptables -A FORWARD -i eth0 [-s, --source [!] address[/mask]] -o ppp0 -j ACCEPT

e.g: user$ iptables -A FORWARD -i eth0 -s 192.168.1.45 -o ppp0 -j ACCEPT

altering the packets as they are about to go out

5: user$ sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

and finally set gateway on the client machine, if you are running on Linux you can do it simply by executing this command:

user$ sudo route add default gw   

to configure more complicated gateway you can refer to :

http://newbiedoc.sourceforge.net/networking/homegateway.html

http://www.yolinux.com/TUTORIALS/LinuxTutorialIptablesNetworkGateway.html