In this tutorial, we will show you how to configure your Raspberry Pi to utilize a static IP address.
We will force the Pi to use a static IP by modifying the Raspberry Pi’s DHCP client daemon or using the network tools. The network 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 to use when connecting to a network. In modern Raspberry Pi OS versions, we will need to use network tools instead of editing the DHCPCD file.
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.
In this tutorial, we use the Raspberry Pi operating system. You may or may not be able to set a static IP on other operating systems using these instructions.
As of Raspberry Pi OS Bookworm, you are unable to use the DHCP method and will need to set a static IP using the network manager instead. So, if you are using Bookworm, follow our network manager section otherwise follow the DHCP section.
Equipment List
Here is a list of all the pieces of equipment that I made use of for this Raspberry Pi Static IP address tutorial.
Recommended
- Raspberry Pi ( Amazon )
- Micro SD Card ( Amazon )
- Power Supply ( Amazon )
- Ethernet Cable ( Amazon ) or Wi-Fi ( Amazon )
- HDMI Cable ( Amazon )
- Monitor ( Amazon )
- USB Keyboard ( Amazon )
- USB Mouse ( Amazon )
Optional
- Raspberry Pi Case ( Amazon )
Retrieving the Router IP Address
1. Before we 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
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.
You may also want to get the current DNS server, which you can do by following the next section. Otherwise, move on to using network tools for Raspberry Pi OS Bookworm or DHCP for old versions of the OS.
Retrieving the Current DNS Server
1. Let us retrieve the current DNS server.
We can do this by opening the resolv.conf
configuration file by running the following command.
sudo nano /etc/resolv.conf
Below is the output that you should see from the above command.
# Generated by resolvconf
nameserver 192.168.0.1
Make a note of the IP next to nameserver
.
Exit the nano editor by pressing CTRL + X.
You should now have the router IP and the nameserver IP. You can now move to network tools for Raspberry Pi OS Bookworm or DHCP for old versions of the OS.
Static IP Address Using the Network Manager CLI
This section will go through the steps of setting a static IP address on your Raspberry Pi if you are running the latest version of Raspberry Pi OS. If you have an older version of the OS, please use the old DHCP method.
1. To begin, you will need to retrieve the router IP address and the current DNS server IP address if you haven’t already done so.
2. You can use either nmcli or nmtui to access the network manager tools on your Raspberry Pi. We will use nmtui as it offers a text-based GUI that is a bit easier to understand and navigate than the nmcli (Command Line) version.
Enter the following command to bring up the network tools in your terminal.
nmtui
3. On the first screen, you will be greeted with three options. Select edit a connection.
4. On this page, you will see all your possible network connections.
Navigate to the one that you wish to have the static IP. In our case, it is HOME_LINK, which is a Wi-Fi connection.
5. You will now see a range of information about the connection you selected. To set a static IP address, you will want to navigate to <Automatic> next to IPv4 CONFIGURATION and change this to <Manual>.
Now navigate across to <SHOW> and press enter.
You should see a range of fields that you need to fill out. We will cover each of these fields in the next step.
6. You will need to fill in the following fields with the relevant information.
Addresses (1): Enter the IP address you want to assign to your Raspberry Pi. Ensure this is not an IP that could be easily attached to another device on your network.
Gateway (2): Enter the router IP address you retrieved earlier in this tutorial.
DNS Servers (3): Enter the IP of the domain nameserver you want to utilize. This address is the nameserver IP you wrote down from earlier in this tutorial. Alternatively, you can use a third-party one such as Google’s “8.8.8.8
” or Cloudflare’s “1.1.1.1
“.
7. Navigate down the edit connection and select <OK>.
8. Now select the <BACK> option.
9. On the last page, you will want to select Quit.
10. For our changes to take effect, you will need to restart the network manager. Luckily, this is as simple as running the following command.
sudo systemctl restart NetworkManager
You will lose the network connection for a few seconds, but the connection should recover.
11. You can now proceed to testing the static IP address.
Static IP Address using DHCP
If you use Raspberry Pi OS 12, please follow the network manager section.
1. To begin, we will need to first retrieve the router IP address and the current DNS IP address.
2. 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
3. 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 your “wlan0
” (Wi-Fi) connection. Decide which one you want and replace “<NETWORK>
” with it.
Ensure 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.
Replace “<ROUTERIP>
” with the IP address that you retrieved earlier in this tutorial
Finally, replace “<DNSIP>
” with the IP of the domain nameserver you want to utilize. This address is either the IP you got earlier in this tutorial or another such as Google’s “8.8.8.8
” or Cloudflare’s “1.1.1.1
“.
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.
4. Now that we have modified our Raspberry Pi’s DHCP configuration file to 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 “dhcpd.conf
” file.
Run the following command to restart your Raspberry Pi.
sudo reboot
Testing the Static IP
1. Once your Raspberry Pi has rebooted, you should be able to connect using the IP address you specified.
If you are connecting locally and want to verify that the static IP address is set correctly, you can run the hostname command.
hostname -I
From this command, you should now be able to see your new static IP address. If it is the IP you expected, you have successfully set up a static IP address on your Raspberry Pi.
192.168.0.88
Conclusion
Using a static IP will come in handy when you need to remember the IP, such as when using FTP or setting it up to act as a NAS.
I hope this Raspberry Pi static IP tutorial has helped you achieve your task. If you have any feedback on this tutorial, please don’t hesitate to leave a comment.
Hi – I have a raspberry pi4 with a recent (may 2024) install of debian and all updates. I have used the raspberry pi installer to do this.
However, when I follow the nmtui method, it will not take due to permissions. But i created the install with my credentials on the setup function for the card and it will not work.
Anyway to get around this? I want to use the the Pi for piHole
Try using sudo with the nmtui method, this should avoid any permission errors.
sudo nmtui
I don’t think this is how to change DHCP reservation anymore.
I’ve now tried it on 2 different Pi’s (4B and 5) on two types of OS and this never works as dhcpcd.conf is always empty.
I’ve seen another way using mtui command
Thank you for pointing this issue out. We have updated the tutorial so that it covers using the nmtui (Network Manager) to set a static IP. Please let us know if you have any issues!
Hi, thank you for this tutorial.
Can I set up two different Static IPs at the same time. One to access via wlan0 and one via eth0? or would that create a conflict?
I can’t see how this will a problem if each interface has a unique static IP address.
Step #3 does not work for me? I don’t get a file with the list of items that i need to changes in step #4.
Hi Mark,
Is the file completely empty? If so, what operating system are you running on your Raspberry Pi?
If it’s not empty then that should be correct, you will be adding lines to the bottom of this file rather than changing ones inside it.
Cheers,
Emmet
Excellent tutorial, simple and accurate.
Thankyou.
Chalk me up also to a BIG Thanks! Very nicely done and very easy to follow along! No more IP changes to the Pi now at random intervals!
Thanks for your work in providing this and other tutorials. It is greatly appreciated!
thank you really much, i needed to check 3 tutorials and yours finally say that it should be “wlan0” and not “wlan” like by other tutorials
I have a R Pi 4 with 8G ram and loaded with 64 bit OS. I have just run these steps and it still works great with 64 bit.
Thank you
A lot has changed recently on Rasbian OS & Buster. This is no longer the way to configure the network, but I don’t understand the new way yet!
Hi Ken,
These steps should continue to function with Raspberry Pi OS (Raspbian) Buster.
There has been no major changes in the way OS handles its DHCP client.
Cheers,
Emmet
I did this on the new raspberry pi os (raspberry pi 4 4gb ram) and it worked perfectly fine
Thank you very much for this easy to understand tutorial!
The vertical bar was some search for my azerty windows keyboard (on the pi) lol.
For anyone interested you have to hold down “altgr” and press the “& 1” key.
Great guide, easy to follow and fixed my issue. Thanks!
Great tutorial, worked immediately! Thanks
hello, How can i get back to DHCP.
Remove the lines we added in step 4 from the dhcpcd.conf file, and reboot. That should revert you back to your original settings.
At step Nr 2 for the command ‘sudo nano /etc/resolv.conf’ I get:
# Generated by resolvconf
nameserver 104.145.255.226
nameserver 104.145.255.227
I did not get “domain home” as the first line (after # Generated…)
Which IP address to use? Or does it matter? Can you explain why two IP addresses?
–Thank you and regards, Larry
Hi Larry,
All you need is the two IP’s mentioned next to nameserver. There is two defined as one is used as a fallback if the first fails.
In Step 7 when replacing you are able to add multiple IP’s as long as they are seperated by a space. So for your case you would end up with.
Cheers,
Emmet
Something I have to do all the time and never remember. Thanks for the easy to follow tutorial!
I noticed quite a few different angels of the same Pi case on here. Could you tell me where to get that case?
Hi,
That is the Raspberry Pi 3 case from KKSB cases. They’re pretty cool designs, and their new Pi 4 case is nice as well.