Raspberry Pi Wifi Static IP Address

I’ve had a Raspberry Pi for a number of years before I decided to actually start playing around with it. I used to sit in the other room where my wireless router is and connect my RPi with a ethernet cable. But I wanted to have it wireless, so I could use my RPi it in my room. It took me a long time to manage to get the Wifi working. I looked at many different websites and forums. I finally got it working and here’s my solution.

I have my adaptor plugged in to my Raspberry Pi without any other USB devices. Once set up I now log in to my Raspbery Pi over SSH. My Wifi network is secured with WPA2. I wanted to use a static IP address so I can easily connect to it using SSH.


Getting it working

Configure the Network Interface

First I edited the network interface file.

sudo nano /etc/network/interfaces

For the wlan0 interface (For the wireless connection) I set up my static IP. I found some posts on forums saying to add the SSID and wireless key in here. However everytime I tried, it would never connect. I found other places using the ‘wpa_supplicant’. After trying different configurations I managed to get the ‘wpa_supplicant’ working perfectly.

allow-hotplug wlan0
iface wlan0 inet static
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

The configuration should look like this.


Then save the file with CTRL + o and close nano with CTRL + x

Setting up wpa_supplicant

Next I opned up the wpa_supplicant config file.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Here is my configuration, under I will explain each part.

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

ssid The name of your wifi network

proto RSN is for WPA2. You can use WPA for WPA1

key_mgmt WPA-PSK is the pre-shared key setting.

auth_alg OPEN is needed for WPA & WPA2

psk The pre-shared key AKA Your Wifi Password

Again save (CTRL + o) and close Nano (CTRL + x).

Reboot and test

Try rebooting your Pi and it could connect over WiFi.

sudo reboot

And finally

There seems to be many ways of setting up WiFi on the Pi, this is just one way that I have managed to get working.