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 192.168.1.100 for public network & 10.10.0.10 for private network on Linux1.
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
please check through ping command from linux2 to linux1 and make it sure you can get ping success to 10.10.0.10
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 yahoo.com from linux2, it will be successful.