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.allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface demo inet static
address 192.168.0.4
netmask 255.255.255.0
gateway 192.168.0.1
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.network={
ssid="BotThoughts"
scan_ssid=0
key_mgmt=NONE
priority=5
id_str="demo"
}
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.network={
ssid="your-ssid-here"
scan_ssid=0
psk="your-pre-shared-key-here"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
priority=1
id_str="demo"
}
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.auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.0.5
netmask 255.255.255.0
gateway 192.168.0.1
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.4
netmask 255.255.255.0
gateway 192.168.0.1
wpa-passphrase yourpassphrasehere
wpa-ssid yourssidhere
wireless-channel yourchannelhere
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp
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.
pi@raspberrypi:/etc/network$ sudo ifup wlan0
ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
pi@raspberrypi:/etc/network$
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.
pi@raspberrypi:/etc/network$ ifconfig -a
eth0 Link encap:Ethernet HWaddr b8:27:eb:fb:8d:50
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:36 errors:0 dropped:0 overruns:0 frame:0
TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3480 (3.3 KiB) TX bytes:3480 (3.3 KiB)
wlan0 Link encap:Ethernet HWaddr 80:1f:02:86:ef:61
inet addr:192.168.0.4 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38 errors:0 dropped:1467 overruns:0 frame:0
TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:841044 (821.3 KiB) TX bytes:100717 (98.3 KiB)
pi@raspberrypi:/etc/network$ ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_req=1 ttl=64 time=3.07 ms
64 bytes from 192.168.0.1: icmp_req=2 ttl=64 time=1.90 ms
^C
--- 192.168.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 1.905/2.491/3.077/0.586 ms
^C
Et voila, you have a wifi static IP. Congratulations!
Did this help you? If so, do me a favor and share via redit, twitter, Google+, etc. Thanks!
Hi man! I am new to raspberry pi, Wheezy also making me more frustrate. I am really confused with Ethernet. please provide me a brief tutorial for Ethernet.
ReplyDeleteEthernet is just the low level standard/protcols that connect your computer to a hub/switch with wires. What are you having problems with?
DeleteMany 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...
ReplyDeletePhilippe (France)
@Philippe It makes my day to hear that! Really happy I could help. It may help others find this if you +1 / like / whatever else. :) Take care!
DeleteGreat job!
ReplyDeleteCan I set the IP addresses the same for wired and wireless?
As long as you don't have ethernet and wifi active at the same time, each adapter could be assigned the same IP address. I'd have to do some research to do anything more than that.
Deletegreat post! i hope this will solve my problem when i got home tonight.
ReplyDeletejonel
Hi - After trying about 10 sets of solutions your post has fixed it for me as well. Thanks.
ReplyDeleteThank you thank you thank you!!!
ReplyDeleteI've been trying to get this to work all day and this is the only solution that has worked, I owe you a pint! You truly are a saint.
Like the other Anonymous of Feb 11, I'd done several searches and yours were the only instructions that worked - many thanks!
ReplyDeleteJust wanted to say thanks. Works sweet with Occidentalis v0.2
ReplyDeleteJust wanted to say after trying quite a few things both online and just tinkering, this just worked, no messing with it, just save it and go. So, uh, thanks! =D
ReplyDeleteAfter a lot of searching on the net and even more trail and error. Nothing worked
ReplyDeleteThis one does!!!
Thanx a lot, this just made my day :)
Thanks man, great of you.
ReplyDeleteThank you very much.
ReplyDeleteWorks perfect, great to have both eth0 and wlan configured with static ip's on the same lan.
ReplyDeleteFinally a tutorial that worked. You're the best, Cheers!
ReplyDeleteVery 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.
ReplyDeleteThe best explanation I found! Thanks a lot man!
ReplyDeleteThe best tutorial I found on internet by far! Thanks a lot man!
ReplyDeleteIs there a way to configure a static wireless IP while at the same time using wpa_supplicant.conf.
ReplyDeleteIf I do that then, I get an error saying, "Cannot use Static method with wpa_supplicant.conf"
Thanks for your article.
ReplyDeleteIs 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.
ReplyDeleteI 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).
This is the output I am seeing:
pi@raspberry-torrentbox ~ $ sudo ifdown wlan0
Ignoring unknown interface wlan0=default.
pi@raspberry-torrentbox ~ $ sudo ifup wlan0
iwconfig: unknown command "GHz"
wpa_supplicant: wpa_action is managing ifup/ifdown state of wlan0
wpa_supplicant: execute `ifdown --force wlan0' to stop wpa_action
run-parts: /etc/network/if-pre-up.d/wpasupplicant exited with return code 1
RTNETLINK answers: File exists
Failed to bring up wlan0.
Any help appreciated!
Jimmy
@Jimmy either put in quotes or if that doesn't work escape the space with a \ character. If that still doesn't work it's probably easier to just use roaming. Thats what I do now.
DeleteThis comment has been removed by the author.
ReplyDelete