Turning your laptop into a wired to wireless router for your wirelessly challenged friends

2008-05-25 12:23:29 PST

Tags: , , ,

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.

3 Responses to “Turning your laptop into a wired to wireless router for your wirelessly challenged friends”

  1. I do this at home, because my landlord only supplies internet over 802.11, which I dislike. At the moment I am using Linux for this purpose, however eventually I plan to try it with FreeBSD, since its wireless support is far less of a kick in the nuts than Linux’s. Try it, you’ll see!

    Anyway, at first I tried just bridging the wireless and ethernet interfaces — no luck. Apparently this has to do with the AP not wanting to talk to devices which haven’t registered their hardware address — such as the other ethernet devices. So I suspect hacking something which registers additional hardware addresses using the same interface might work, though I haven’t tried it.

    Two strategies remain. The simplest is to enable proxy-ARP, and add host-routes to all your ethernet hosts. This has a substantial advantage for LAN parties: now the wireless and ethernet hosts are all on the same broadcast domain!

    The other strategy is to give your ethernet interface a separate subnet, and have the other hosts use that interface’s address as their default route. You could run DHCP here. There is a major caveat: most APs are way too rigid to let you add a route to your box for that second subnet, nor will they do NAT for it. So you need to be running some decent software on the AP — openwrt or whatever, or have a proper box acting as an AP.

  2. I tried just bridging the wireless and ethernet interfaces — no luck. Apparently this has to do with the AP not wanting to talk to devices which haven’t registered their hardware address — such as the other ethernet devices. So I suspect hacking something which registers additional hardware addresses using the same interface might work, though I haven’t trie

  3. I’m going to do something really stupid here. I’m in need of help with this same situation, only in Windows. So if anyone would write me privately at adapt at kc dot rr dot com I would really appreciate it. Basically I’m blind using talking screen reading software. I’m going in a week or so to a place where their is only wireless internet, and I need to attach my IP phone to the Ethernet port of my Windows XP based laptop so I can work. I hate to bug you very intelligent Linux users about a Windows problem, but this blog entry was the only one I could find that was even close to describing what I need. Tried network bridging but, then it won’t connect to the wireless network any more, maybe because I think you need three adapters, one with internet connnection sharing enabled, and the other two for the bridge. Am I wrong about that? There has to be an easy way to do this. Thanks in advance for any ideas.

Leave a Reply

Valid XHTML 1.0!
Valid CSS!
Mindstab.net is proudly powered by WordPress
Entries (RSS) and Comments (RSS).
20 queries. 0.420 seconds.