Staticfree Blog

Back to the main blog

Wed, 10 Mar 2004

Get you 'net on

Typing this at ~100KPH en-route to Rochester, NY. I'm traveling with Leighton and so I felt it was a fun chance to attempt to share my 'net connection with him. The easiest way to do such is to let him connect to my laptop via WiFi while my computer is connected via my cell phone. It's a bit of voodoo magic to get it going, but once it's up - it's pretty keen.

'Net → cell provider → cell phone via. GPRS → my laptop via. Bluetooth → his laptop via. NAT and ad-hoc WiFi.

See the complete entry to get the technical details on how to set it up in Linux.


I'm setting this up on a Debian GNU/Linux (testing) and using the BlueZ packages.

The cell → laptop connection is pretty easy, if you have Bluetooth. I put together the necessary files to get it going on my Debian system, but it might be useful for other things as well. See my pages on connecting a Nokia 3650 phone to Debian GNU/Linux for GPRS via Bluetooth.

The rest gets a bit hairy. You first need working wireless drivers that can do ad-hoc mode. You can generally enable this mode by doing something like: iwconfig wlan0 mode ad-hoc essid foobar, set the IP address: ifconfig wlan0 192.168.1.101 and bring up the interface ifconfig wlan0 up. I set the wireless connection's local IP address to 192.168.1.101, which will be seen below for the DHCP server. You could add this to your /etc/network/interfaces file and use mapping to optionally use it. It's a bit of a pain to use, though.

You also need IP Tables support in your kernel to enable NAT. I won't go over that here, as there are many howtos on the subject. Once you have the appropriate IP Tables setup going (just installing it, with NAT support), you should get a DHCP server running so that any connecting clients can auto-configure. I just grabbed the dhcp Debian package from apt and set it up as follows:

/etc/dhcpd.conf:


subnet 192.168.1.0 netmask 255.255.255.0 {

   range 192.168.1.102 192.168.1.255;
   option routers 192.168.1.101;
   option domain-name-servers 192.168.1.101;
}

As you can probably see, I say that the local wireless connection is the DNS server. That makes it so that I don't have to deal with sending the actual DNS IPs to the client, whatever they might be. To make this go, I grabbed the dnsmasq package which functions as a DNS cache/proxy. I left the default options for that one (except for it to not listen on my wired interface).

With all that, I finally enabled NAT to the appropriate interface. I want packets to come in from the client through wlan0 (my wireless interface) and get NATted through ppp0 (my cellmodem). I put together the following script to get it all going:

rc.nat_ppp0:


#!/bin/sh

echo 1 > /proc/sys/net/ipv4/ip_forward
modprobe ipt_MASQUERADE
iptables -t nat -F
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

With the ad-hoc wireless up and running successfully, anyone who sets their machine to the same channel/essid should be able to connect to the node, send a DHCP request, get back server configuration, and then share your [meager] Internet connection. Of course, this applies to any 'net connection, not just one connected via cellmodem.

Aside: I know I'm not being thorough here, but this is more of a note to myself about how to do it and a hint to those who wish to follow my steps, than a step-by-step guide. Linux can be confusing - especially as it's full of so many undocumented hacks. #include "documentation.txt" :-)

trackback enabled

Comments