How Do I Set a Static IP Address on Raspberry Pi?

How Do I Set a Static IP Address on Raspberry Pi
How Do I Set a Static IP Address on Raspberry Pi

A static IP address is very useful if you use your Raspberry Pi as a homeserver or need to access it from another device. This will ensure that you can find your Raspberry Pi at the same fixed IP address each time it reboots, instead of having a dynamic address. This helps to avoid confusion if you have multiple Raspberry pi devices connected to your network.

It’s easy and fast to create a Raspberry Pi static IP. This article will show you how to change your IP address in Raspberry OS to make it permanent.

What is an IP Address?

An Internet Protocol address (IP) is used to identify every device on a computer network or network. More on that later. The IP address is usually written in “dot-decimal” notation. This means that four decimal numbers are separated by dots, each one ranging from 0 through 255. is an example.

Raspberry Pi OS is a Linux-based operating platform. By default, the Raspberry Pi’s IP address gets reconfigured every time it is rebooted. This can cause it to change. This is not ideal if you need to connect to your Raspberry Pi from another device such as a server. It is better to create a static IP address for Raspberry Pi.

Private vs. public IP

To identify your local network, a public address is used. This address is usually changed every time your router connects with the internet. However, depending on your internet service provider, you might be able make it static.

You can locate the public IP address of a Linux system like Raspberry Pi OS. This can be done by using a Terminal command or by simply doing a search on the internet for “What’s my IP?” This is required only if you want to connect to a device outside of your network. We won’t discuss this here.

Instead, we will be looking at private addresses that are used to identify devices on your local network. Although it is possible to reserve an address for your Raspberry Pi’s wireless router, we will be showing you how to assign a static IP directly from your Raspberry Pi.

1. Configuration of DHCP

Raspberry Pi OS, formerly known as Raspbian, uses DHCP (Dynamic Host Configuration Protocol) to automatically assign an IP address every time it reboots. Learn more about DHCP .

Get into the Cyber Security Career now!

You will need to change the behavior of Raspberry Pi OS so it uses the same static IP addresses every time.

You will need information about your network setup before you can add the necessary details to the configuration file. The following information is required:

* Type of network connection. If your Raspberry Pi is connected wirelessly to the router, this is WLAN or Ethernet.

* Raspberry Pi’s current IP address. It’s best to use this to assign its static IP to ensure that it hasn’t been used by another device on your network. If it isn’t, ensure that another device doesn’t have it.

Enter the following command into a Terminal window to find the Raspberry Pi’s IP address:

hostname I

* The router’s gateway IP address is the address used to reach it via the local network. It is not the public IP. This can vary depending on router models, but it usually starts at 192.168.

Enter the following command to find it. Note the first IP address you are given.

ip r | grep default

* The DNS (Domain Name System IP) address of your router. This address is usually the same as the gateway address. However, it may be changed to an alternate DNS value, such as or for Cloudflare.

Enter the following command to find the DNS IP address at the moment:

sudo nano /etc/resolv.conf

Take note of the IP address following nameserver. This is the DNS address. To close the file, press Ctrl+ X.

2. Add static IP settings

Once you’ve gathered all the information you need for your network connections, you can edit the DHCPCD.conf configuration file and add the settings that you need to create a static IP address on your Raspberry Pi.

sudo nano /etc/dhcpcd.conf

You can edit the file if you have not edited it before. It will contain several comment lines, preceded by a # symbol. Add the following lines to the bottom of the file, replacing the bolded names with your network details:

interface NETWORK static ip_address=STATIC_IP/24 static routers=ROUTER_IP static domain_name_servers=DNS_IP

You can replace the bolded names with these:

NETWORK Your network connection type is eth0 (Ethernet), or wlan0(wireless).

STATTIC_IP is the static IP address that you wish to assign for the Raspberry Pi.

ROUTER_IP is the gateway IP address of your router on the local network.

DNS_IP is the DNS IP address. This address is usually the same as your router’s gateway address.

Here’s an example configuration that will set the static IP at and allow wireless connectivity to a router at

interface wlan0 static ip_address= static routers= 
static domain_name_servers=

After you’ve entered the settings, press CTRL + X then Y and EnTER to close the configuration file.

3. Reboot Raspberry Pi

After the HTMLcpcd.conf configuration file has been modified, restart the Raspberry Pi to make the changes and to set the static IP address.

sudo reboot

Instead of using an address automatically assigned by DHCP the Raspberry Pi will attempt to connect using the static IP address you have set in the dhcpcd.conf.

Enter the following command to verify that it works correctly:

hostname I

Now you should see the static IP address you have set in the DHCPCD.conf configuration.


Congratulations! Your Raspberry Pi has now set up a static IP address. It should automatically retain this address whenever it boots up. You can now use your Raspberry Pi system as a NAS or media server and connect to it at the same fixed Raspberry Pi IP address each time.

Mark Funk
Mark Funk is an experienced information security specialist who works with enterprises to mature and improve their enterprise security programs. Previously, he worked as a security news reporter.