Sharing an Internet connection
This article is intended to allow you to use an Internet connection (e.g making use of the PPP protocol) through the routing of IP packets by the machine connected to the Internet.
Routing of IP packets
Consider the following: a class C network (254
IP),starting at 192.168.0.0
with a subnet mask: 255.255.255.0
To configure our gateway, you must first know the version of the core: 2.0, 2.1 or 2.2, 2.3 or 2.4.
The tools being are different.
Here is how to proceed under Linux 2.0 kernel:
/sbin/modprobe ip_masq_ftp (to route FTP)
/sbin/modprobe ip_masq_irc (to route IRC)
/sbin/modprobe ip_masq_quake (to route Quake game server)
/sbin/modprobe ip_masq_raudio (to route real audio)
echo 1 > /proc/sys/net/ipv4/ip_forward
To route the connection:
ipfwadm -F -a m -S 192.168.0.024 -D 0.0.0.0/0
Which means that everything having as source the 192.168..0 network is routed directly to the Internet.
For the Linux kernel 2.1 and 2.2, the procedure is almost identical, simply change ipfwadm by ipchains.
ipchains -A forward -s 192.168.0.0/24 -d 0.0.0.0/0 -j MASQ
Under the Linux kernel 2.3 and 2.4 the procedure is almost identical, simply change ipfwadm by iptables.
iptables -A POSTROUTING -t nat -o ppp0 -j MASQUERADE
Orginal document published by Rémy Pouchain