Static fixed and wifi IPs on Raspberry Pi

When coding to and configuring ones Raspberry Pi, it is convenient to have it on a wired connection, but when it is being deployed in the field, it is much easier to have it on wifi.

Still, it can be immensely useful to have it’s IPs always be fixed, making surveillance etc a breeze (or more breezely, to be exact) and thus here’s a quick guide to making that happen. There are other tutorials on this, but most are about fixed IP for either eth0 or wlan0.

Without further ado, on to /etc/network/interfaces:

iface eth0 inet static
    address 192.168.1.173
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    address 192.168.1.172
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
iface default inet static
    address 192.168.1.172
    netmask 255.255.255.0
    gateway 192.168.1.1

The “trick” is to set a static IP for eth0, configure wlan0 and set a default overall static IP, which will apply to wlan0 since there already is an explicit static IP for eth0It should be possible to reference the wlan0 blurb via using id_str=”wlan0″ in wpa_supplicant.conf, but alas, that doesn’t work for me.

Add the necessary network={… blurb to /etc/wpa_supplicant/wpa_supplicant.conf and you’re good to go:

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

network={
  ssid="your SSID"
  psk="yourpassword"

  # Protocol type can be: RSN (for WP2) and WPA (for WPA1)
  proto=RSN

  # Key management type can be: WPA-PSK or 
  # WPA-EAP (Pre-Shared or Enterprise)
  key_mgmt=WPA-PSK

  # Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
  pairwise=TKIP

  # Authorization option should be OPEN for both WPA1/WPA2 (in less 
  # commonly used are SHARED and LEAP)
  auth_alg=OPEN
}

Issue a quick

pi@raspberrypi ~ $ sudo ifup wlan0

And verify with

pi@raspberrypi ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:95:ca:9e
          inet addr:192.168.1.173  Bcast:192.168.1.255  Mask:255.255.255.0
          ...

wlan0     Link encap:Ethernet  HWaddr 4c:60:de:5d:7e:6a
          inet addr:192.168.1.172  Bcast:192.168.1.255  Mask:255.255.255.0
          ...

 

This entry was posted in Linux, Networking, Raspberry Pi. Bookmark the permalink.

Leave a Reply

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