Pages

Friday, January 18, 2013

Raspberry Pi Wifi Static IP

My RPi is going to be a telepresence robot so it uses wifi. It also needs a static IP address. Here's how to configure Raspbian Wheezy with a static IP for wifi. Included are two useful techniques. Follow the series of steps and options below.

You can configure Wheezy for 1. Roaming with Static IP, below, or 2. Static IP With No Roaming, WPA2, PSK, below.

1. Roaming With Static IP

By default, Wheezy is configured for wireless roaming using wpa_supplicant, a daemon that manages roaming and authentication to access points with WPA, WPA2, WEP, or no encryption. With it, you can specify multiple access points and your RPi will join them automatically. First you'll need to add a Static IP Configuration, below.

a. Static IP Configuration

First, edit your /etc/network/interfaces and add the following to specify a static IP for demo which is any arbitrary name that we can use in the wpa_supplicant.conf to associate any network with this static IP configuration. You'll also make sure you have your wlan interface configured correctly.

Next, you'll configure wpa_supplicant. Add a specification for a network Without Encryption below, With Encryption, WPA2, PSK below, or Any Network Specification below.

b. Without Encryption

To specify a network without encryption, edit /etc/wpa_supplicant/wpa_supplicant.conf, add your network specification to the end of the file as follows. Specifying key_mgmt=NONE says the AP does not require encryption. To use the static IP configuration that you added in your interfaces, set id_str="demo" or whatever name you chose.

2b. With Encryption, WPA2, PSK

To specify a network with WPA2 encryption using PSK (pre-shared key), edit /etc/wpa_supplicant/wpa_supplicant.conf, add a network specification to the end of the file as follows. To use the static IP configuration that you added in your interfaces, set id_str="demo" or whatever name you chose.

2c. Any Network Specification

The bottom line is that you can add any network specification, following various online examples, to wpa_supplicant.conf and use a static IP for that access point simply by adding id_str="demo" or whatever name you chose in interfaces.

In fact, you can have multiple strings, like home, work, traveling, demo, etc. Once you have edited wpa_supplicant.conf and interafaces, proceed to the 3. Final Steps below.

2. Static IP With No Roaming, WPA2, PSK

This config does not use wpa_supplicant and is for WPA2 personal with PSK (Private Shared Key). The changes to your /etc/network/interfaces file will result in something like the following.

Specify using static instead of manual for interface wlan0, then specify the address, netmask, and gateway, configure the WPA passphrase and SSID, and the wireless channel. Finally, you have to disable the wpa_supplicant configuration, and you have to disable the default dhcp behavior.

Proceed to 3. Final Steps below.

3. Final Steps

After making your configuration file changes, either reboot, or issue the following commands to restart the wlan0 interface:

sudo ifdown wlan0
sudo ifup wlan0

If you get no errors on the last command, except possibly some ioctl errors, you're a-ok.

Double-check by issuing iwconfig to make sure the RPi is joined to the access point, then use ifconfig wlan0, make sure it's configured correctly, then issue a ping to your gateway (ping 192.168.0.1) and then ping google.com or some other reliable website.

Many thanks! After many searches on the Internet, you're the only one who provides the right solution to configure two static IP addresses for both eth0 and wlan0 (and that allows the WiFi interface to work without the Ethernet cable to be connected). You made my evening...Philippe (France)

Very helpful ... works as advertised, and straightforward to do. My complication was that I had a couple of network={} profiles in the wpa_supplicant.conf file that conflicted (associated with a newer router in a different location but with the same ssid): I had to comment one of those out to get it to work. For those that follow, if it doesn't work for you first time, look for conflicting definitions [you can comment them out with a leading '#']. I tried a couple of other methods before finding Michael's, but this one works.

Thanks for your article.Is there a way to specify a static ip address for wlan0 while at the same time using wpa_supplicant.conf. If I do that, I get an error to the effect .... "Cannot use static method with wpa_supplicant.conf"

Hello Thanks for the Tutorial it's a good one but I am having a few problems.

I tried to set up according to: 2. STATIC IP WITH NO ROAMING, WPA2, PSK

The two problems are that I don't know how to enter my SSID and my wireless channel because they both have whitespaces in them. I entered "2.4 GHz" for the channel (because that is the frequency on this network).