January 06, 2013

Why Linux rocks

... or how to share your internet connection.

I'm out of town for a conference.  I brought my laptop and tablet PC with me.  Unfortunately, the hotel room doesn't have wireless -- it only has a LAN port.  How can I access the internet through my tablet?  Well, since the laptop has a functioning wireless card, it's not that difficult.  You need to run hostapd, a daemon that implements a wireless Access Point (AP) in software, and bridge-utils to bring the LAN and wireless interfaces.  On Ubuntu, these are available directly through apt-get.  From there, it's relatively straight forward:

  1. Configure the AP (edit /etc/hostapd/hostapd.conf to specify SSID, access keys, etc.)
  2. Configure the bridge (edit /etc/network/interfaces to specify the interfaces you want to bridge, the gateway and DNS servers)
  3. Restart networking services
  4. Connect to the created wireless AP and enjoy your bridged connection
For parts 1 and 2, I used the settings from the original post directly.  I had to change eth1 to eth0 since that's what the LAN interface is called on my system.  The IP addresses for the laptop, gateway and DNS server were also obviously different, but readily available through netstat -nr.  If you skip step 2, then you won't be get an IP address at step 4 unless DHCP is running on the laptop.  If step 2 is performed correctly, then whatever is performing DHCP on the remote side of the LAN connection will perform the IP address allocation and everything will work alright.

It's amazing what you can do just by editing a couple of configuration files.  Of course, it would be great if all this would all be done through a GUI.  There's already nm-applet, which seems to allow one to create an AP, but I couldn't get that going, so I gave up and headed for the command-line option.