Say you're at a party and the only internet is a wireless router and for whatever reason, no one can plug into it. Wireless internet only. You with your fancy laptop are sitting pretty and this is just fine. They your friend shows up lugging his clunky old desktop that only has an ethernet port for internet connectivity. Is he out of luck? Turns out not, because you an come to the rescue!
It's really easy, especially with Ubuntu.
To start with, you need to be a router, so you need firewall software that can do NAT (network address translation). This is part kernel side (NAT and iptables options enabled and modules loaded) and part user space side, in the form of the program 'iptables', so make sure it is installed, which it is by default on Ubuntu (I think).
Now all you really need to do is add two routing rules, one says anything coming on the ethernet port should go through the NAT procedure, which basically means it's IP headers are tweaked to make it look like they originated from your computer and then you send them along to the internet. The second rule helps facilitate this (I'm a little less sure what it does, but it's needed).
In this case we are assuming the interface eth0 is the wired network and eth1 is the wireless. Change as required.
iptables --table nat --append POSTROUTING --out-interface eth1 -j MASQUERADE iptables --append FORWARD --in-interface eth0 -j ACCEPT
Next you just need to tell the kernel port forwarding should be turned on, and you can do this through the wonderful /proc filesystem.
echo 1 > /proc/sys/net/ipv4/ip_forward
Now you're pretty much ready to go. Connect to the wireless, presumably though NetworkManager or your wireless toll of choice. Then enable the wired network manually.
ifconfig eth0 up 192.168.1.1
This turns on eth0 with a local network address of 192.168.1.1. Now plug your friend's computer into the ehternet port with a crossover ethernet cable or into a hub and then the hub into you with regular ethernet cable and have them manually pick an address on 192.168.1.* (or whatever local network you chose, it doesn't matter) and set you (192.168.1.1) as the gateway router.
If this is a little much for them or they are running an OS that makes this non trivial, than its really another easy step for you to set up a DHCP server and do all the configuration for them :).
So install dhcpd, on Ubuntu it's 'dhcp3-server', on Gentoo I think it's just 'dhcpd'.
Now we have to configure it. We have to tell it the gateway router, which is us (192.168.1.1), the nameservers (the servers in /etc/resolv.conf) and the pool of IPs to use and what interface/network to listen on.
Open the config file, on Ubuntu '/etc/dhcp3dhcpd.conf'.
The relevant parts are as follows
...
# servers in /etc/resolv.conf
option domain-name-servers 192.168.0.1;
...
# the local network you created
subnet 192.168.1.0 netmask 255.255.255.0 {
#IPs free to assign
range 192.168.1.100 192.168.1.200;
#your computer, the router
option routers 192.168.1.1;
}
And that's it. (Re)Start the server
/etc/init.d/dhcp3-server restart
And you are now serving all the information your friend's computer will need to automatically connect properly.
They should now be online once they restart their internet connection.
One annoying thing about Ubuntu vs Gentoo is that on Ubuntu, the init system is a bit more kludgy and old fashioned. Any server software installed is automatically configured to start at boot time, forever, which in this case isn't what you want. You only want the dhcpd server to run very rarely, at parties, the rest of the time it's a waste. So we need to turn it's auto starting off. Apparently the /ubuntu init system barely supports this, we have to force it.
update-rc.d -f dhcp3-server remove
Now just turn it on when you need with its init.d file.
May 25, 2008 08:23 PM :: British Columbia, Canada 














He drove past me going about 65, I was doing 60. I then caught up to him, and as soon as I passed him, he slowed down to about 2 car-lengths behind me, pressed the gas just a bit, and I'll be darned if I didn't hear the unmistakable sound of the supercharger waking up.


