In this Raspberry Pi static IP tutorial, we will show you how to configure your Raspberry Pi’s network so that it utilizes a static IP address.
We will force the Pi to use a static IP by making modifications to the Raspberry Pi’s DHCP client daemon. This software controls the way the operating system handles IP addresses.
By Modifying the DHCPCD config file, we can tell the software the local IP address that it should use when connecting to a network.
In addition to defining the static IP address on your Raspberry Pi, we recommend that you also set it on your router.
Setting it on the router helps ensure that your router doesn’t assign the IP address to a different device before your Raspberry Pi connects.
You can also change the MAC address of the Raspberry Pi. This change can be handy in a variety of scenarios.
Here is a list of all the pieces of equipment that I made use of for this Raspberry Pi Static IP Address tutorial.
Setting up a Static IP Address on the Raspberry Pi
We make use of the Raspbian operating system in this tutorial. You may or may not be able to set a static IP on other operating systems using these instructions.
1. To begin setting up a static IP address on our Raspberry Pi, we will first need to retrieve some information about our current network setup.
Let’s first retrieve the currently defined router for your network by running the following command.
ip r | grep default
By using this command, you should get a result similar to the one we have below.
default via 192.168.0.1 dev eth0 proto dhcp src 192.168.0.159 metric 202
Make a note of the first IP mentioned in this string.
For example, the IP that we will make a note of from this command is “
192.168.0.1“. This IP address is the current router address.
2. Next, let us also retrieve the current DNS server.
We can do this by opening up the “
resolv.conf” configuration file by running the following command.
sudo nano /etc/resolv.conf
From this command, you should see the lines of text below.
# Generated by resolvconf nameserver 192.168.0.1
Make a note of the IP next to “
nameserver“. This will define the name server in our next few steps.
3. Now that we have retrieved both our current “router” IP and the nameserver IP we can proceed to modify the “
dhcpcd.conf” configuration file by running the command below.
This config file allows us to modify the way the Raspberry Pi handles the network.
sudo nano /etc/dhcpcd.conf
4. Within this file, enter the following lines.
First, you have to decide if you want to set the static IP for your “
eth0” (Ethernet) connector or you “
wlan0” (WiFi) connection. Decide which one you want and replace “
<NETWORK>” with it.
Make sure you replace “
<STATICIP>” with the IP address that you want to assign to your Raspberry Pi. Make sure this is not an IP that could be easily attached to another device on your network.
<ROUTERIP>” with the IP address that you retrieved in step 1 of this tutorial
Finally, replace “
<DNSIP>” with the IP of the domain name server you want to utilize.
This address is either the IP you got in step 2 of this tutorial or another one such as Googles “
220.127.116.11” or CloudFlare’s “
interface <NETWORK> static ip_address=<STATICIP>/24 static routers=<ROUTERIP> static domain_name_servers=<DNSIP>
Now save the file by pressing CTRL + X then Y followed by ENTER.
5. Now that we have modified our Raspberry Pi’s DHCP configuration file so that we utilize a static IP address, we need to go ahead and restart the Raspberry Pi.
Restarting the Raspberry Pi will allow our configuration changes to be loaded in and the old ones flushed out.
Upon rebooting, the Raspberry Pi will attempt to connect to the router using the static IP address we defined in our “
Run the following command to restart your Raspberry Pi.
Testing the Static IP
1. Once your Raspberry Pi has finished restarting you now should be able to connect using the IP address you specified.
If you are connecting locally and want to verify the static IP address set correctly, you can do that by running the following command.
From this command, you should now be able to see your new static IP address. If it is the IP that you expected, then you have now successfully set up a static IP address on your Raspberry Pi.
Using a static IP will come in handy when you need to remember the IP such as using FTP or setting it up to act as a NAS.
I hope that this Raspberry Pi static IP tutorial has helped achieve your task. If you have any feedback on this tutorial, then please don’t hesitate to leave a comment.