-
RPi: Static WiFi Addressing
Having configured ssh on the Raspberry Pi for public keys, the next step is to cut the cord by configuring the USB WiFi dongle to automagically come up with a static IP.
[Update: As of 2017, set a static IP by tweaking
/etc/dhcpcd.confinstead. Search the blog for that to find recent descriptions. ]Make
/etc/network/interfaceslook like this:auto lo iface lo inet loopback #iface eth0 inet dhcp auto eth0 #iface eth0 inet static iface eth0 inet manual address 192.168.1.209 gateway 192.168.1.1 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 allow-hotplug wlan0 #iface wlan0 inet manual iface wlan0 inet static address 192.168.1.9 gateway 192.168.1.1 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 #wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp
Then set up
/etc/wpa_supplicant/wpa_supplicant.confthusly:ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="whatever it might be" psk="choose your own password" }You want different IP addresses for the eth0 and wlan0 devices, because you never know when you’ll be forced to use them at the same time.
Using
wpa-confrather thanwpa-roamprevents the machinery from automagically doing things when you’re not watching.The router can hand out IP addresses based on MACs, but that means bottling up all that configuration in a single device that might go toes up. Forcibly configuring each device to a static IP adds a bit of resilience to the network, right up to the point where you must change all of them at once.
Alas, the router seemed to lose track of the Pi after a day. Pinging from my desktop box reported
Destination Host Unreachable, even though signing on through the USB keyboard showed the USB WiFi link (a netis WF2123) was still up. Signing on to the router and refreshing the DHCP list (even though the RPi has a static IP) knocked things loose: suddenly the RPi became pingable.It seems the WiFi link turns itself off after a while, which can be averted by tweaking the options:
sudo nano /etc/modprobe.d/8192cu.conf # Disable power saving options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
The WordPress sourcecode tag seems to turn underscores into blanks [Update: on the last line of a sourcecode block, which I’ve now forced to be a blank line] ; the options should read
rtw_power_mgmtandrtw_enusbss, respectively.Anyhow, the
rtw_enusbssoption prevents the USB interface from going down. It was already zero in the default configuration, but I presume there’s no harm in clearing it again.