Introduction
Stuck in a hotel room with one internet connection and three computers? At a client site with need for a half-dozen connections but no one brought a switch and cables? Visiting relatives for a few days and you tire of cycling the power on the DSL router to trick it into using your laptop?
If your laptop has a modem + on-board NIC or on-board NIC + AirPort, you can, with relative ease, quickly build a router that will enable one or more computers to connect to the internet through your laptop, creating a temporary local area network (and an acute sense of genius when you amaze your associates, family, or friends :).
The following HOWTO is built around an old "toilet seat" G3 iBook with 802.11b AirPort card and on-board 10/100 NIC. In this case eth1 (AirPort) maintains the connection to the internet while eth0 (on-board 10/100 NIC) offers a cable connection to one or more computers that do not have wireless ability.
Configure the DHCP server.
- Configure the device that will connect to the internet (on-board NIC, AirPort, or modem) and connect to the internet.
Then use the Network Config tool (YDL Menu --> System Settings --> Network) to set a static IP address for either your
on-board NIC or AirPort, such as that given below:
cat /etc/sysconfig/network-scripts/ifcfg-eth0 [ENTER]
... which will look something quite similar to:DEVICE=eth0 BOOTPROTO=static ONBOOT=yes NETMASK=255.255.255.0 IPADDR=192.168.10.1 GATEWAY=192.168.10.1
- Now temporarily disable eth0:
ifdown eth0 [ENTER]
- Config /etc/dhcpd.conf to tie to the static IP you assigned to eth0 (above) as follows:
ddns-update-style none; option domain-name "earthlink.net, terraplex.com"; option domain-name-servers 66.7.161.1, 66.7.161.3; authoritive; subnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.10 192.168.10.20; option routers 192.168.10.1; }
- Configure IP masquerading (which enables a set of IPs to function on one NIC that are not related to the IP assigned
to another NIC on the same computer):
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE [ENTER]
iptables-save [ENTER]
/etc/init.d/iptables save [ENTER]
cat /proc/sys/net/ipv4/ip_forward [ENTER]
(returns 0)
echo 1 > /proc/sys/net/ipv4/ip_forward [ENTER]
(sets kernel arg to 1)
cat /proc/sys/net/ipv4/ip_forward [ENTER]
(returns 1)
- Re-enable eth0:
ifup eth0 [ENTER]
- Restart dhcp:
service dhcpd restart [ENTER]
- Make certain dhcp is running:
ps -aux | grep dhcp [ENTER]
- Monitor dhcp activity:
tail -f /var/log/messages [ENTER]
- Connect and enable a dhcp client (whose on-board NIC or AirPort must be set to DHCP as follows):
DEVICE=eth1 BOOTPROTO=dhcp ONBOOT=yes
Reconfiguring the ip route table
- View the current route settings (wanting eth1 (wireless) to be "default", not eth0)
route [ENTER]
... which will produce something like this:Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.0 * 255.255.255.0 U 0 0 0 eth1 192.168.10.0 * 255.255.255.0 U 0 0 0 eth0 127.0.0.0 * 255.0.0.0 U 0 0 0 lo default 192.168.10.1 0.0.0.0 UG 0 0 0 eth0
... where eth0 (the built-in NIC) is the default and this is not good because we want eth1 to be the default path as it is how we will get to the outside world. Therefore, we must change this, as follows:
route del default gw 192.168.10.1 [ENTER]
route add default gw 192.168.2.1 [ENTER] - Check the route table again:
route [ENTER]
... which should produce something like this:Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.0 * 255.255.255.0 U 0 0 0 eth1 192.168.10.0 * 255.255.255.0 U 0 0 0 eth0 127.0.0.0 * 255.0.0.0 U 0 0 0 lo default 192.168.2.1 0.0.0.0 UG 0 0 0 eth1
- Give it a test drive!
ping terrasoftsolutions.com/products/ydl [ENTER]
This HOWTO was prepared by Kai Staats, Terra Soft Solutions, Inc.





