How to Setup a Static IP Address on Raspberry Pi

Setting up a static IP address on Raspberry Pi is an intelligent idea if you're using it as a home server or often need to access it remotely from another device. This means you'll always be able to locate it at the same fixed Raspberry Pi IP address, rather than a new address being set dynamically every time it reboots. This is also useful for avoiding confusion when connecting many Raspberry Pi devices to your network.

Fortunately, once you know how to set a Raspberry Pi static IP address is relatively simple and quick. We'll show you how to change your IP address permanently on Raspberry Pi OS.

What Is an IP Address?

Each device on a computer network, or the network itself on the internet (more on that later), is uniquely identified by an Internet Protocol (IP) address. Four decimal integers, ranging from 0 to 255, are separated by dots to form the IP address, often written in “dot-decimal” format. A case in point is

Your Raspberry Pi's IP address may well vary since Raspberry Pi OS, a Linux-based operating system, by default automatically configures it each time you reboot it. This is not ideal if you want to connect to the Raspberry Pi from another device and require a stable address, such as if you're using it as a server. Therefore, setting a static IP address on a Raspberry Pi is preferable.

Private vs. Public IP

Your local network on the wider internet is identified by a public IP address. This typically varies each time your router connects to the internet; however, depending on your internet service provider, you may be able to keep it static.

On a Linux system, such as the Raspberry Pi OS, you may get the public IP address by running a special Terminal command or simply conducting a web search for “What's my IP?” It is only required if you wish to connect to a device outside your network, which we will not discuss here.

Instead, we'll look at the private IP addresses that each device on your local network uses to identify itself. While it may be feasible to reserve a specific address for your Raspberry Pi in your wireless router's settings for the same reason, we'll show you how to set a static IP from the Raspberry Pi itself.

1. DHCP Configuration

Raspberry Pi OS (formerly known as Raspbian) uses DHCP (Dynamic Host Configuration Protocol) to automatically provide an IP address to the Raspberry Pi whenever it reboots.

You will need to modify the DHCP client daemon's configuration file, dhcpcd.conf, to change the Raspberry Pi OS' behavior so that it uses the same static IP address each time.

To add the required details to the configuration file, you will first need some information about your network configuration setup. You need the following information:

  • a network connection type If your Raspberry Pi is wirelessly connected to the router using a cable, this is wlan0; otherwise, it is eth0.
  • To be sure that the Raspberry Pi's current static IP address hasn't previously been assigned to another device on the network, it is safest to reuse it. If not, make sure another device isn't using it.

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

hostname -I
  • The IP address used to connect to your router from the local network is its gateway IP address, not its public IP. Typically, it starts with 192.168 but varies based on the router model.

Enter the command and take note of the first IP address provided to find it:

ip r | grep default
router gateway IP
  • The DNS (Domain Name System) IP address of your router Typically, this is the same as the gateway address, but it may be set to a different value to use a different DNS, such as for Google or for Cloudflare.

Enter the following command to find the current DNS IP address:

sudo nano /etc/resolv.conf
Raspberry Pi DNS IP

Note the IP address after nameserver – that's the DNS address – and then press “Ctrl + X” to close the file.

2. Add Static IP Settings

Now that you've gathered all of your network configuration information, it's time to change the dhcpcd.conf configuration file to add the settings you need to set up a static IP address on Raspberry Pi:

sudo nano /etc/dhcpcd.conf

The file will mostly consist of different comment lines preceded by a hash (#) symbol if you haven't already modified it. Add the following lines at the bottom, replacing the names in bold with your personal network details:

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

Replace the emboldened names as follows:

  • NETWORK: Your network connection type is either eth0 (Ethernet) or wlan0 (wireless).
  • STATIC_IP: the static IP address you want to set for the Raspberry Pi.
  • ROUTER_IP: the gateway IP address for your router on the local network
  • DNS_IP: the DNS IP address (typically the same as your router’s gateway address).

With a wireless connection to a router at, here is an example of a static IP configuration that is set to

interface wlan0
static ip_address=
static routers=
static domain_name_servers=
Raspberry Pi dhcpcd static IP configuration

Once the settings have been entered, press “Ctrl + X“, followed by “Y” and “ENTER” to close and save the modified configuration file.

3. Reboot the Raspberry Pi

Restart your Raspberry Pi using the dhcpcd.conf static configuration file to take effect of the changes and set a static IP address for it:

sudo reboot

The Raspberry Pi will now try to connect to the router using the new static IP address that you set in the dhcpcd.conf file rather than one that was automatically assigned by DHCP.

To check that it is working correctly, enter the following command:

hostname -I

You should now see the static IP address that you set in the dhcpcd.conf configuration file.

Raspberry Pi static IP set

Set a Static IP Address: Success

Congratulations! You've set up a static IP address on Raspberry Pi, and it should now use that address whenever it starts up. You may now use your Pi system as a NAS, media, or gaming server and connect to it using the same fixed Raspberry Pi IP address every time.

Oh hi there It’s nice to meet you.

Sign up to receive awesome content in your inbox, every month.

We don’t spam! Read our privacy policy for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *

20 Easy Raspberry Pi Projects Toys, Tools, Gadgets

20 projects using the Raspberry Pi, a tiny and affordable computer, for beginners looking to make cool things, Projects are explained with full-color visuals and simple step-by-step instructions.