Set a Static IP Address on a Raspberry Pi

by | May 1, 2016

Setting a static IP on a Raspberry Pi has the advantage of giving you a known IP address each and every time you power up your Pi, this can be helpful if you are running your Pi as a web server or want to connect via SSH. In this example, I am assuming that you are running the latest version of Raspian and have completed the initial setup of your Pi.

 

Materials

 
In this tutorial I will be using the following materials:
 

 

Connect to the Raspberry Pi

 

First you need to access the Command Line Interface (CLI), you can do this either via SSH with Putty if you already know the IP address of your Pi or if you have a monitor connected with the desktop screen you can access the command prompt via the main menu – Menu/Accessories/Terminal as shown below.

Putty connection using IP address

 

Raspberry Pi Main Menu

 

Set an Ethernet Static IP

 

To set a static IP address you will need to access and edit the dhcpcd.conf file using the following command

 

 

You should now be in editing mode and see the following screen, using the down arrow scroll to near the bottom of the file.

 

dhcpcd screen shot

 

There you will see the entry “Example static IP configuration:”, to configure a static IP for the Ethernet (eth0) you will need to remove the “#” where appropriate and edit the values below to suit your network.

The static routers and static domain_nameservers settings should be set to your router address, this is generally

  • 192.168.0.1
  • 192.168.1.1
  • 10.1.1.1

A sticker on your router normally shows this.

The static ip_address should take the same form as you static router eg 192.168.1.xxx, just change the last number, in this case, I have chosen 130 but you can choose any number between 2-254 (don’t forget the /24 on the end), if you have a lot of devices already connected to your network then you may want to pick a higher number so you don’t get conflicts.

 

 

Your dhcpcd.conf file should now look something like this, note that I have left the # in place with regards to the static ip6_address. If you want to set a static ip6 address, remove the # and enter the address then add the # back to the static ip_address line above.

 

Raspberry Pi dhcpcd eth0 config

 

To exit the editor, press ctrl+x

To save your changes press the letter “Y” then hit enter

To complete the changes enter the following command

 

 

To confirm that your changes have been successful log back into your RPi using the static ip_address you selected above and enter the following command:

 

 

Raspberry Pi eth0 ifconfig output

 

If all has gone well you have now successfully set up your Ethernet static IP.

 

Set up a Wi-Fi Static IP

 

Configuring a static IP for Wi-Fi is done in much the same fashion, first enter the following command to  open and edit the /etc/dhcpcd.conf file

 

 

Enter the following details below the previous eth0 example to create a wlan0 entry.

Note: This IP address can be the same as your ethernet one in most cases as if they are both active your router will give priority to the wired ethernet connection.

 

 

Your dhcpcd.conf file should now look similar to this.

 

Raspberry Pi eth0 and wlan0 config

 

To exit the editor, press CTRL+X, then “Y”, then hit Enter

To complete the changes enter the following command

 

 

Again, to confirm that your changes have been successful log back into your RPi using the static ip_address you selected above and enter the following command:

 

Raspberry Pi ifconfig output

 

The wlan0 address has now been set to our static IP address (Note the wired ethernet cable is not installed).

If all has gone well you have now successfully set up your Wi-Fi static IP as well.

If you have any thought’s about this article, improvements or errors let me know in the comments below and if you found this helpful, why not share it with others.

Pin It on Pinterest

Share This