Sharing wireless connection with wired computer

Yesterday I wanted to install Arch Linux on a brand new mini computer (with Quad-Core Atom!). I did that on wired connection in one place and then wanted to install additional packages at home.

Problem is: I only have wireless connection at home. So I decided I’ll share wireless connection using my laptop connected to a switch. Here is a diagram of my setup:

The hardest part was finding manual how to do this that is on the right level of advancement. There are plenty of descriptions how to create a corporate-level network and configure that with loads of features. And they’re all far too long and quite an overkill for my purposes.

The solution I came up with comes from many sources, most notably Arch Linux wiki pages about basic routing and dnsmasq. The rest is manual pages and various other sources.

Install iptables and dnsmasq. Both are needed for this setup. First one will handle forwarding packets from “Laptop sara” and “Laptop router” subnets. The second is a relatively tiny DNS and DHCP server.

Configure dnsmasq. In router’s subnet ip’s are from 192.168.1.1-255 range. dnsmasq will use eth0 interface and assign ip’s from 192.168.2.2-255 range. Here is /etc/dnsmasq.conf that will do that:interface=eth0
expand-hosts
domain=localdomain
dhcp-range=192.168.2.2,192.168.2.10,1h
dhcp-host=sara,192.168.2.3 # static assignment
#log-dhcp # usefull for debugging
log-queries # less spam than above, can be left enabled

192.168.2.1 will be used as eth0’s address. This one is simple: “ifconfig eth0 up && ifconfig eth0 192.168.2.1”. I also had to turn of wicd connection manager daemon, since it used to disconnect me from wired connection from time to time for no real reason: “/etc/rc.d/wicd stop”.

All that is left is making sara ask for assignment: “sudo dhcpcd” and done. We are up and running!