How to give the Raspberry Pi a Static IP Address

I use my Raspberry Pi in a header less mode over WiFi, but every time I turned it on I found that a different IP address had been assigned. This made life a little difficult, so I searched the internet for an answer.

I found many suggestions , and eventually found a method that worked for me. First run the WiFi Config from the desktop and get the wireless working. Restart the Pi with
sudo nano shutdown -r now

Watch on the monitor screen and when the request for password comes up just look above this and the current IP address is shown mine was 192.168.1.9 this will depend on how many other devices are connected to the router. Start the desktop up and confirm that an entry for your network has been created

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

There should be an entry showing your network details, for example

ssid= “your SSID” etc

Now you need your gateway address, this can sometimes be found printed on your router or you can enter

sudo route -nee

Make a note of the gateway address. Now you need an unused IP address, try to keep this well clear of addresses assigned by your router. Try 192.168.1.255 and check this is not used by

ping “192.168.1.255” -b

Stop at any time with Ctrl C.

If it does not say Destination Host Unreachable then try 192.168.1.254 etc until you find a free address. Now you need to edit the interfaces file

sudo nano /etc/network/interfaces.  Find the line after allow -hot plug wlan0 that reads

iface default inet dhcp

And change this to

iface default inet static

And add the following lines

address 192.168.1.255 # use your address here
netmask 255.255.255.0
gateway 192.168.1.1. # use your address here

Save the file and exit nano.

Reboot your Pi with sudo shutdown – r and check your new IP address has been used with

sudo ifconfig

And check the block wlan0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s