Here I have mentioned How to setup a NAT server in Linux in just few servers with the help of iptable.
In my scenario I have tested with Red Hat enterprise Linux 6(Kernal 3.5) but I think I should work with most of linux kernels .
In my Environment there are two lan card on my linux system where I want to setup NAT server.
I am assuming a well configured linux system where iptable and network connectivity is working with two NIC card and IP address configured are :
IP=184.108.40.206/24 and gateway =220.127.116.11
(In most of practical scenario eth0 is given as public ip provided by your ISP)
Now login to terminal with superuser (root)
First you need to tell your kernel that you want to allow IP forwarding.
Now configure iptables to forward the packets from your internal network(192.168.0.0), on /dev/eth1, to your external network(18.104.22.168 i.e provided by your ISP) on /dev/eth0. You do this will the following commands:
Now now open /etc/sysctl.conf in your editor (in my case I am using vim)
Change the line that says to
Now now edit in your editor (in my case I am using vim) make sure that:
, , are all set to 'yes'.
Reboot machine and you are done.