Title: Share the internet connection
Author: Sandro Tosi
Last modified: 2006-05-15 (2005-05-30)
Suppose this configuration: Pc1 directly connected to internet and Pc2
connected to Pc1 via an ethernet link. Now you what to surf the stormy
ocean of internet from Pc2: what do you have to do?
First of all, set Pc1 as the default gateway for Pc2: you could do
this by modifying file /etc/network/interfaces or using ifconfig. To
identify Pc1 you should use its IP on the lan, not the one assigned to
Than, on Pc1, you should enable forwarding, directly inside kernel or
by launch this command (as root):
# echo 1 > /proc/sys/net/ipv4/ip_forward
To keep this configuration even after reboot, there are some different
ways to do:
1. add the line ``FORWARD_IPV4=true'' in /etc/sysconfig/network ;
2. add the line ``ip_forward=yes'' in /etc/network/options ;
3. add the line ``net.ipv4.ip_forward=1'' in /etc/sysctl.conf, and run
``sysctl -p'' to reload configuration without a reboot.
Still on Pc1 and still as root, you should enable the masquerading:
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
supposing ppp0 is the interface to internet: every packet exiting from
ppp0 will be masquered. Kernel should be compiled with ip_masq_* and
iptable_nat on (even as modules).
Remember to set up DNS entries in /etc/resolv.conf !
A good document for masquerading is ``Linux IP Masquerade HOWTO''
available at http://www.tldp.org/HOWTO/IP-Masquerade-HOWTO/