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:
Network 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.

So, how to achieve what I wanted?

  1. 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″.
  2. 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.
  3. 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

    Of course we need to enable dnsmasq: “/etc/rc.d/dnsmasq start”.
  4. Configure iptables. Simple and fun:
    iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE # note the use of 'wlan0' here
    /etc/rc.d/iptables save
    /etc/rc.d/iptables start

  5. 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”.
  6. All that is left is making sara ask for assignment: “sudo dhcpcd” and done. We are up and running!
About these ads

~ by Tener on 07/01/2010.

One Response to “Sharing wireless connection with wired computer”

  1. After trying a lot of things with NetworkManager, this was VERY helpful :)

    Thanks for sharing.

    Mooddha

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: