A wireless, headless Linux box

If you’re using wireless networking in Ubuntu (or, presumably, most flavours of Linux), you may have noticed that your network doesn’t connect until you’ve logged in and the NetworkManager’s applet has done its thing. This doesn’t happen for wired networks, where you get a connection as soon as the machine has booted. This is all to do with the extra security requirements of wireless networks, where the user has to select which of the visible networks to connect to, and enter any required passwords. Obviously this can’t be done before the user has logged in to enter these details.

For the most part this isn’t a problem, apart from an occasionally annoying delay while the networking is sorted out before you can get down to some serious work avoidance on the Internet. However, if you want to have a headless computer on your wireless network, for use as a server, MythTV box, or a grunt for distributed rendering, you don’t want to be logging into this machine to get the network going whenever you switch it on. Fortunately, it is possible to get your machine to connect to a wireless network on boot without having to log in. Note that you’ll have to hard-code which wireless network you’re connecting to, but since this is a headless server and presumably somewhere in a dusty corner, that shouldn’t be a problem. So how’s it done? Well, here goes…

Before we start, I’ve made a number of assumptions on your setup, so if your system isn’t covered here, you may need to do a little more research elsewhere. Sorry about that, but I can only advise on what I’ve done with my system.

  • You’ve already got a working wireless network card in your machine. If you need help setting up drivers for it, I’m afraid this isn’t the place. I used the stuff on this page to get my Netgear WG311v3 working.
  • You’re using WPA security on your wireless network. I’m not getting into the arguments here.

First off, make sure you have the wpasupplicant package installed, which will handle the security side of the wireless networking for us. (You are using WPA security, right?) It’s almost certain that this is installed, but we’d better check now before we cut the machine off from the Internet.

sudo apt-get install wpasupplicant

Now, as I’ve already mentioned all network connections are handled by the NetworkManager, so if we want to do our own thing we need to get rid of it. Note that once we’ve done this your machine won’t have any network access, so make sure you’ve got another machine close by in case of need. You can do this in two ways – either disable NetworkManager (something of an arcane process), or more simply (and the way I did it) remove the relevant packages:

sudo apt-get remove network-manager network-manager-gnome

OK, so now you have a machine with no networking capability at all. Never fear, though: your machine will soon be out of solitary confinement. Using your favourite text editor in sudo mode, edit the file /etc/network/interfaces and set it up as follows:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet dhcp

wpa-ap-scan 1
pre-up sudo /sbin/wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -Dwext -B
pre-up sleep 5
post-down sudo killall -q wpa_supplicant

So, what has this done? Well, the first couple of lines set up the loopback network device, which is used for all sorts of things in Linux. Don’t ever get rid of this unless you like a lot of pain in your life.

The second two lines tell the system that we want the wlan0 interface (that’s the wireless one) to get going automatically, and acquire an IP address through DHCP. The final chunk tells the system how to go about setting up the connection:

wpa-ap-scan 1

This setting means that the ESSID of your wireless network is publicly visible. If your router hides the ESSID, set this to 2.

pre-up sudo /sbin/wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -Dwext -B
pre-up sleep 5

This specifies the command to be used to set up the wireless connection. -i is the name of the interface, -c specifies the location of the configuration file (more on this in a moment), and -B runs wpa_supplicant in the background (very important!). The -D option sets the type of driver to be used. The wext driver is fine in most cases, even if you’ve set up your network card’s drivers through ndiswrapper.

The final stage is to configure wpa_supplicant so it knows about your wireless network. In the interfaces file, we specified that the configuration file is located at /etc/wpa_supplicant.conf, so edit that file. The contents of the configuration file should be as follows:


        ssid="<your SSID>"
        psk="<your wireless network's password>"
        proto=RSN WPA
        pairwise=CCMP TKIP

The ctrl_interface line tells wpa_supplicant where to dump any information it needs while it’s running. The setting here is the default, and I see no reason to change it. Below that is simply the details of your wireless network. Note that the ssid and psk value must be in quotes. The other values seem to work well for most wireless network situations.

That should be all you need to do. To see if it’s worked, reboot the machine. If you’ve set up an SSH server, you should be able to log in remotely straight away. Or, take a look at the list of devices connected to your wireless router, and you should see that it’s connected itself without your intervention. Now you can stick the machine in its dusty corner and let it do its thing.

The wireless network card in my machine unfortunately doesn’t support Wake-On-LAN. If it did, I could stick my server in the attic and never look at it again. Maybe I’ll try that one day.


  1. Hi Steve,
    thanks for this excellent acticle, it was exactly what I was looking for and it works for me!
    I use a FITPC2 (very small PC) running Ubuntu 11.10, RaLink RT3090 Wireless, WPA, using a static IP address.

Leave a Reply