Assign a static IP address to the wireless network interface on Raspberry Pi


To easily access our wireless Raspberry Pi projects (like the Pi Rover) over SSH, FTP, HTTP or whatever, we want to assign a static IP to the WLAN interface. In this example the network address is and the Pi should be at (which falls outside the DHCP pool starting at The router is at

Configure WiFi

Once the WiFi dongle is plugged in, the easiest way to configure it is to run WiFi Config from the graphical desktop in Raspbian. Simply let it scan for the available network and connect to it. This will save some network specific settings to /etc/wpa_supplicant/wpa_supplicant.conf.

/etc/wpa_supplicant/wpa_supplicant.conf example:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev


Configure a static IP address

Now you can edit /etc/network/interfaces to define a static configuration for wlan0. Change ‘iface wlan0’ from ‘dhcp’ to ‘static’ and add the IP definition of your LAN and the wlan0 interface as follows:


auto lo
auto wlan0

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet static
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Make sure to include the ‘auto lo’ as well. Without the loopback you’ll end up in a world of misty symptoms, whereof an extremely slow SSH login is just an example.

EDIT: On Jessie the proper way to assign a static IP would be to configure the interface in /etc/dhcpcd.conf (and reboot to get rid of the ‘secondary’ assignment, see ‘ip addr’):


static interface wlan0
static ip_address=
static routers=
static domain_name_servers=

Guarding the connection

You may not need this, but in my setup the WiFi connection sometimes completely freezes. This might be caused by the adapter driver, but it seems more likely to be caused by a bug in the router. The remedy is to restart the interface, which, of course, can be quite a challenge if there is no connection at all. So I created a simple script:

wget -q --tries=10 --timeout=20 --spider > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
    sudo ifdown wlan0
    sleep 3
    sudo ifup wlan0

This is called every five minutes from the crontab of a sudoer:

*/5 * * * * /home/pi/

One thought on “Assign a static IP address to the wireless network interface on Raspberry Pi

Leave a Reply