Configuring a Raspberry Pi's WiFi and Static IP
This is for my own reference but it might prove useful for others as well.
When starting a new Pi project from a fresh installation I often need to recall the steps to connect to wifi with a static IP. Often, but not often enough for me to commit it to memory.
For future me, these are those steps.
Update the firmware
This isn't required for the networking, per se, but can help ensure the Pi is up to date.
$ sudo rpi-update
Customize the Pi
$ sudo raspi-config
- Change the default user's password
- Set a hostname
- Enable SSH access
Set a static IP address
Record the current network details
$ ifconfig
Make a record of the inet addr, bcast, and mask
$ route -nee
Record the route as the "gateway address".
edit the network interface
$ sudo nano /etc/network/interfaces
Find the line similar to iface eth0 inet dhcp
or iface eth0 inet manual
.
Replace it with: (using the relevant addresses collected above)
iface eth0 inet static
address 192.168.128.11
netmask 255.255.255.0
broadcast 192.168.128.255
gateway 192.168.128.1
Automatically connect to wifi
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add the credentials to the bottom of the configuration file:
network={
ssid=""
psk=""
}
With the network name and password in the quotes.
Restart the interface:
$ sudo wpa_cli reconfigure
Sanity check:
$ ifconfig wlan0
Reboot
Finally, restart the device and we're good to go!
$ sudo shutdown -r now