1. Use the Command Line:
The easiest way to set a static IP address on your Raspberry Pi is to use the command line. To do this, open the terminal window and type the following command:
sudo nano /etc/dhcpcd.conf
This will open the dhcpcd.conf file in the nano text editor. Scroll down to the bottom of the file and add the following lines:
interface eth0
static ip_address=192.168.1.10/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
Replace the IP addresses with the ones that are appropriate for your network. Once you have done this, press Ctrl+X to save and exit. Then, type the following command to restart the network interface:
sudo service networking restart
2. Use the Raspberry Pi Configuration Tool:
The Raspberry Pi Configuration Tool is a graphical user interface that allows you to easily set a static IP address on your Raspberry Pi. To open the tool, type the following command in the terminal window:
sudo raspi-config
This will open the Raspberry Pi Configuration Tool. Select the “Network Options” option and then select “IP Address”. Enter the static IP address that you want to use and then select “OK”.
3. Use the Network Interfaces File:
The network interfaces file is a text file that contains the configuration for the network interfaces on your Raspberry Pi. To edit this file, type the following command in the terminal window:
sudo nano /etc/network/interfaces
This will open the network interfaces file in the nano text editor. Scroll down to the bottom of the file and add the following lines:
auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
Replace the IP addresses with the ones that are appropriate for your network. Once you have done this, press Ctrl+X to save and exit. Then, type the following command to restart the network interface:
sudo service networking restart
When you plug a Raspberry Pi into the network and boot it, it will generally get a “random” IP from the DHCP server. This IP address might change almost every time you use it, which is not convenient at all. Let’s learn how to fix it, and tell the Raspberry Pi to always use the same one.
There are three ways to set a static IP address on Raspberry Pi: assign an IP address to your Raspberry Pi in the router configuration, set a static IP in the desktop environment, or change the dhcpcd.conf configuration file to always use the same IP.
We’ll explore these 3 methods, but first, let’s make sure you understand your current network, it’s an important prerequisite to avoid any IP address conflicts or network malfunctions.
If you’re looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.
Prerequisites: Get the network configuration
I put the word “random” in quotation marks in my introduction because there is nothing truly random with computers. Before picking an IP address and trying to configure it on the Raspberry Pi, we need to take a few minutes to study the current network.
Get the IP address of your router
On most networks, especially at home, the main router is your Internet provider box. It provides Internet access for all devices and is often the DHCP server too (the main equipment in charge of assigning IP addresses to all devices).
By accessing its web interface, you can generally get a clearer overview of the network configuration.
If you don’t know its IP address, it should be mentioned as “gateway” in the network configuration of any computer connected to the Internet. It’s often the DNS server too.
From a Raspberry Pi or Linux computer, you can use this command to find the IP address:route -n
In my case, my router IP address is 192.168.222.1 (because I configured it). But in most cases, it will be 192.168.1.1 or 192.168.1.254.
Once you have the IP address, you can try to access the web interface via your web browser. It will be password protected, so you may need to find your Internet provider documentation to access it.
Set a static IP for the Raspberry Pi on the router
If the network main router is also the DHCP server, the easiest way to set a static IP address for the Raspberry Pi is to use its web interface. We call this a DHCP lease, and it’s possible to set a static lease for any equipment already connected to the network.
The interface will be slightly different for each provider and router brand, but in my case, it looks like this:
I can pick the name of any device on my network, and set a static IP address. I can also enter a MAC address if the device is not listed (here is how to find the MAC address on Raspberry Pi).
If you can find something similar on your router, it would be the easiest solution. Nothing to change on the Raspberry Pi, and even when you reinstall the Raspberry Pi, it will stay with the same IP address.
It will also avoid most issues as it’s configured directly on the DHCP server.
Get the DHCP range
If you can’t or don’t want to use this recommended method, you need a bit more information before configuring the Raspberry Pi manually.
First, you need to find the DHCP range. In general, you have a network that goes from 192.168.1.1 to 192.168.1.254, but the DHCP range is maybe only from 1.100 to 1.150. This will be useful to avoid any conflict.
We don’t want to set the Raspberry Pi IP address to 1.110 if the DHCP may assign it to your computer.
You can also find this information in your DHCP server configuration (so your Internet provider router in most cases). For me, it looks like this:
Well, I guess my configuration is not typical, as it covers all the IP addresses, probably because I changed it.
A smart move, if you have something similar, would be to reduce the range (from 222.2 to 222.100 for example).
Anyway, we’ll do a quick audit after that to choose a free IP address.
If you find that your DHCP range is from 1.100 to 1.150 for example, we’ll just avoid picking an IP address in this range. You can for example use 1.160 if it’s not taken by another device with a static IP.
How do you know? That’s the last step before changing the Raspberry Pi configuration.
Get a list of the currently used IP addresses
To be safe, it’s a good practice to get a list of the IP addresses that are currently used on the network. This can be done from the router interface directly, or via a network scan.
On the router configuration page, you may have access to a list of all the computers and other devices connected to your network, with their current IP addresses. Not only the one assigned by the DHCP server but all of them.
This will give a good overview of the current state of the network. If you can’t find this, don’t worry, you can also do a network scan.
From a Windows computer, you can use the Advanced IP Scanner tool, which will give you something like:
And on Linux, you can install nmap with:sudo apt install nmap
And use it to do a network scan:nmap -sP <network> | grep report
So, for example:
In most cases, your DHCP server assigns IP addresses at the beginning of the range. In both examples, all IP addresses are given between 2 and 40. IP addresses 100 and 150 are static IPs.
So, if I pick something like 200 for my Raspberry Pi, it should be safe (192.168.222.200).
At this point, you should know which IP address you’ll configure on your Raspberry Pi. I’ll give you 2 methods, one from the desktop environment, and the other one in the command lines.
Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands at your fingertips.
Set a static IP on Raspberry Pi OS Desktop
On Raspberry Pi OS with Desktop, we can set a static IP address by editing the wireless and wired network settings from the top menu.
Here are the exact steps:
- Right-click on the network icon in the right corner of the top panel.
- Choose “Wireless & Wired Network Settings”.
- I’m doing this procedure for the wired connection (eth0), but it works the same way for the Wi-Fi connection (wlan0).
- Fill the form with your network configuration, for example:
- Take a free IP address to put in the “IPv4 address”. If possible, try to pick something outside the DHCP range. But in general, DHCP servers are smart enough to not assign an IP address that is already taken.
Don’t forget the network mask at the end (/24) or it won’t work. - The router IP address we got earlier with:
route -n - And the DNS server is often the same for a home network.
You can either check your current configuration with:
cat /etc/resolv.conf
And use the same IP. Or use a public DNS server, like the one offered by Google (8.8.8.8) or OpenDNS (208.67.222.222).
If you use Pi-Hole or AdGuard, you obviously need to adjust this and set it to the other Raspberry Pi IP address. - Click “Apply” to save the changes, and then “Close” (it doesn’t close automatically).
- Take a free IP address to put in the “IPv4 address”. If possible, try to pick something outside the DHCP range. But in general, DHCP servers are smart enough to not assign an IP address that is already taken.
To really apply the changes, you probably need to reboot the Raspberry Pi (main menu > Shutdown > Reboot), unplug/plug the network cable, or disable/enable the Wi-Fi.
After the reboot or reconnection, you can put your mouse over the network icon to find out if your IP address has changed to the configured static IP address (more details here).
Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.
Set a static IP in the command line
On a Lite edition of Raspberry Pi OS, a static IP address can be configured in /etc/dhcpcd.conf. It will force the system to use this IP address instead of the one assigned by the DHCP server.
Here are the steps to follow:
- Open the configuration file with:
sudo nano /etc/dhcpcd.conf
- Paste these lines at the end of the file:
interface eth0
static ip_address=192.168.1.200/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 - Change the interface if needed (eth0 for a wired connection, wlan0 with Wi-fi).
- Change the IP addresses according to your network.
The first one is the IP address you want to use, followed by the network mask (/24 in most cases).
The second is your gateway (the Internet router in general).
And finally, the DNS server (often the router if you didn’t change it).
And that’s it. Once, you have a good idea of your network configuration and know where to change the Raspberry Pi configuration, it’s not that complicated.
I hope this article was useful, and if you want to learn more about network administration, you should check these other tutorials on the website:
Additional Resources
Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now.
Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Download the e-book.
VIP Community
If you just want to hang out with me and other Raspberry Pi fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.
Need help building something with Python?
Create, understand, and improve any Python script for your Raspberry Pi.
Learn the essentials step-by-step without losing time understanding useless concepts.
Get the e-book now.
You can also find all my recommendations for tools and hardware on this page.
3 Easy Ways To Set A Static IP Address On Raspberry Pi
Setting up a static IP address on your Raspberry Pi can seem like a daunting task, but fear not, we’ll walk you through it step by step. In this article, we’ll show you three easy ways to set a static IP address on your Raspberry Pi.
Method 1: Using the Command Line
The first method for setting a static IP address on your Raspberry Pi is to use the command line. To do this, open up a terminal window and type in the following command:
sudo nano /etc/dhcpcd.conf
This will open up the dhcpcd.conf file in the nano text editor. Scroll down to the bottom of the file and add the following lines:
interface eth0 static ip_address=192.168.1.10/24 static routers=192.168.1.1 static domain_name_servers=192.168.1.1
Be sure to replace the IP addresses with the ones that are appropriate for your network. Once you’ve done that, press Ctrl+X to save and exit the file. Then, type in the following command to restart the networking service:
sudo service networking restart
Your Raspberry Pi should now have a static IP address.
Method 2: Using the GUI
The second method for setting a static IP address on your Raspberry Pi is to use the graphical user interface (GUI). To do this, open up the Raspberry Pi Configuration tool by typing in the following command:
sudo raspi-config
This will open up the Raspberry Pi Configuration tool. Select the “Network Options” option and then select “Wi-Fi”. Enter your network information and then select “Static” for the IP address. Enter the IP address, subnet mask, gateway, and DNS servers that are appropriate for your network. Once you’ve done that, press the “OK” button to save your changes.
Your Raspberry Pi should now have a static IP address.
Method 3: Using a DHCP Reservation
The third method for setting a static IP address on your Raspberry Pi is to use a DHCP reservation. To do this, you’ll need to log into your router’s web interface. Once you’ve logged in, look for the “DHCP Reservations” section. Here, you’ll be able to add a new reservation for your Raspberry Pi. Enter the MAC address of your Raspberry Pi and the IP address that you want it to have. Once you’ve done that, press the “Save” button to save your changes.
Your Raspberry Pi should now have a static IP address.
Setting up a static IP address on your Raspberry Pi is a simple process that can be done in just a few minutes. With these three easy methods, you’ll be able to set a static IP address on your Raspberry Pi in no time.