Set up a NAT router on a Linux-based computer- Red Hat Enterprise 5 …!!!


Set up a NAT router on a Linux-based

Suppose you have 2 computers : Linux1  and Linux2.

Linux1 has two Network Cards- eth0 & eth1.  Linux1 is connected directly to the internet through eth0 & eth1 with Local LAN. we will use for public network & for private network on Linux1.

for eth0:

IPADDR= address:



for eth1:

IPADDR= address:


Now on Linux2:

We want to make linux2 have internet access through linux1.

we will set IP for linux2 from same subnet what we configured on eth1 on linux1

for eth0:

IPADDR= address:


please check through ping command from linux2 to linux1 and make it sure you can get ping success to


Now on Linux1 computer and type below commands:

[root@linux1 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@linux1 ~]#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
[root@linux1 ~]#iptables -A FORWARD -i eth1 -j ACCEPT

[root@linux1 ~]#service network restart

Copy the file /etc/resolv.conf from Linux1 to Linux2. We use this file to resolve DNS.

Now ping from linux2, it will be successful.




About Author

Chakraborty Prijus

Former Asst. Manager (IT) - MGH Group MCA (Masters in Computer Application) From Sikkim Manipal University India. Have 5 years experience In IT field.

Leave A Reply

Powered by