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.
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.
So, how to achieve what I wanted?
- Enable kernel routing in laptop. Hardly any manual mention that simple step. The temporary solution is to execute command “echo 1 > /proc/sys/net/ipv4/ip_forward”. Alternatively in /etc/sysctl.conf set “net.ipv4.ip_forward=1″.
- 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:
dhcp-host=sara,192.168.2.3 # static assignment
#log-dhcp # usefull for debugging
log-queries # less spam than above, can be left enabled
Of course we need to enable dnsmasq: “/etc/rc.d/dnsmasq start”.
- Configure iptables. Simple and fun:
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE # note the use of 'wlan0' here
- 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!