How to configure Wireless Lan Raspberry Headless Server

It could be useful for wlan configuration without a Desktop GUI or just from ssh client, you choose why.

The point is: you can’t do it with iwconfig, unless you have just wep encription enabled, if you use to have wpa/wpa2, instead you want to use wpa_supplicant.
If you type

sudo wpa_supplicant --help

you will see a small but useful reference.

At this point you have to consider using your passphrase in two totally different way:

  1. Store it in plain text, as is in the wpa_supplicant.conf (USE DOUBLE QUOTES!!)
  2. Store its WPA PSK generated with wpa_passphrase from an ASCII passphrase (DON’T USE DOUBLE QUOTES!!!).

Before we start: The only way for wpa_supplicant to distinguish between a plaintext passphrase and a wpa psk passphrase is using double quotes.


Case 1 (Storing the passphrase in clear text)

Open and edit wpa_supplicant.conf issuing:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Look at the relevant lines below (again:USE DOUBLE QUOTES!):


Then we need to be sure that ifup will use wpa_supplicant
So let’s edit it by issuing :

sudo nano /etc/network/interfaces

And check the wlan0 (this is how the new wireless lan interface will be called) part to be similar to the following:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#pre-up killall -q wpa_supplicant
pre-up wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
#post-down killall -q wpa_supplicant

As you can see I just commented out the hotplug line, because Raspberry hardware badly tollerates the sudden current draw due to the insertion of the usb wifi network adapter into the usb port. Another situation while using an external powered usb hub, but we want it to be compact, so i didn’t even try that.

At this point we should have finished and you can do two things: reboot or restarting the network.
I suggest you to reboot. Anyway if you just want to restart the network you can issue

service networking restart

It will give some warning…

ifdown wlan0 && ifup wlan0

Now if all goes fine you should see some messages in console about the joining the wi-fi network, asking for a dhcp request ecc ecc.

root@raspberrypi:~# ifup wlan0
wpa_supplicant: wpa_action is managing ifup/ifdown state of wlan0
wpa_supplicant: execute `ifdown --force wlan0' to stop wpa_action
Internet Systems Consortium DHCP Client 4.2.2
Copyright 2004-2011 Internet Systems Consortium.
All rights reserved.
For info, please visit

Listening on LPF/wlan0/7c:dd:90:03:9b:32
Sending on   LPF/wlan0/7c:dd:90:03:9b:32
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to port 67 interval 7
DHCPDISCOVER on wlan0 to port 67 interval 14
DHCPREQUEST on wlan0 to port 67
bound to -- renewal in 42890 seconds.

You can test your config by typing:

ifconfig wlan0

If you find errors like:

rfkill: Cannot open RFKILL control device
Could not set interface wlan0 flags: No such file or directory
WEXT: Could not set interface 'wlan0' UP
wlan0: Failed to initialize driver interface
Failed to bring up wlan0.


root@raspbian:~# wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
 rfkill: Cannot open RFKILL control device
 Could not set interface wlan0 flags: No such file or directory
 WEXT: Could not set interface 'wlan0' UP
 wlan0: Failed to initialize driver interface

Try with:


Case 2 (Storing the passphrase WPA-PSK)

First of all we need to get our psk issuing the command:

wpa_passphrase ssid password

Where you have to replace “ssid” with your wireless network name and “password” with your actual password.

It will output something like :


Store the red values in the mouse clipboard or in a txt file as we are going to use it later.

Now, go to the first part of this article, follow all steps except for the passphrase format in /etc/wpa_supplicant/wpa_supplicant.conf, wich should be without double quotes, like follows:

#File /etc/wpa_supplicant/wpa_supplicant.conf

After a reboot or a network restart (see the commands before) you can check your network card status with

iwconfig wlan0


ifconfig wlan0

Some music while you wait your raspberry to reboot?

(Visited 4,479 times, 1 visits today)

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.