The Raspberry Pi is a tiny, affordable computer that is great for learning programming and electronics. By default, most Raspberry Pi devices connect to the network via DHCP, which means they get assigned a dynamic IP address that can change. For servers and other use cases, having a static IP address that never changes is desirable.
In this comprehensive guide, I‘ll walk through how to set up a static IP on both the Ethernet and Wi-Fi interfaces of the Raspberry Pi running Raspberry Pi OS (formerly Raspbian).
Prerequisites
Before we get started with the static IP configuration, let‘s go over some prerequisites:
- A Raspberry Pi – any model will work
- Raspberry Pi OS installed on an SD card
- Access to the terminal on the Pi either via monitor & keyboard or SSH
- Know the details of your network like the router IP, DNS servers, etc.
If you need help with any of the above, check out my Raspberry Pi setup guide.
Now let‘s get to setting that static IP!
Static IP on Ethernet
Setting a static IP on the Ethernet port of the Raspberry Pi is done by modifying a configuration file called dhcpcd.conf.
-
First, use the
sudo nano /etc/dhcpcd.confcommand to open up the file in the nano text editor. -
Go to the bottom of the file and add the following:
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 1.1.1.1
Let‘s break down what each line means:
interface eth0– Configures the eth0 Ethernet interfacestatic ip_address– Specifies the static IP address and subnet maskstatic routers– Sets the router/gateway IP addressstatic domain_name_servers– Lists DNS servers to use
-
Save the file by pressing Ctrl+X then Y and finally Enter.
-
Reboot your Pi with
sudo rebootfor the changes to take effect.
Once your Pi starts back up, the Ethernet interface should now have the static IP you specified! Verify it with ip addr show eth0.
Static IP on Wi-Fi
The process for setting a static IP on Wi-Fi is very similar to Ethernet.
-
Again edit
sudo nano /etc/dhcpcd.conf -
Add the following block for your Wi-Fi details:
interface wlan0
static ip_address=192.168.1.75/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 1.1.1.1
As you can see, the only difference is specifying wlan0 instead of eth0.
- Save and reboot once more.
Your Raspberry Pi should now have consistent static IPs on both networks! Verify with ip addr show wlan0 after rebooting.
Changing the Hostname
While hostnames don‘t matter much for home usage, setting a custom hostname can make things easier to manage if you have multiple Pis on the network.
To change the hostname:
- Edit the
/etc/hostnamefile withsudo nano /etc/hostname - Change the content to your desired hostname, like
mypi - Save and reboot
Use the hostname command to double check it changed.
Testing Connectivity
At this point we have set custom static IPs and hostnames, but do our network settings actually work? Let‘s test it out.
On another system on the same network, try pinging and SSHing with the new IPs and hostnames we configured.
ping mypi
ssh pi@192.168.1.75
If you get a response, then our static networking is working perfectly!
Troubleshooting Issues
If you encounter issues getting connected or with the Internet not working properly, here are some things to check:
- Verify the correct IP & subnet – Make sure the IP and subnet mask match your network segment.
- Check router config – Some routers block access to certain ports by default. Verify SSH/HTTP ports open.
- Ping gateway – Try pinging the router/gateway IP from the Pi after assigning the static IP. If that fails, connectivity is broken somewhere.
- Flush DNS cache – Sometimes a stale DNS cache can cause issues. Run
sudo systemd-resolve --flush-caches - Reboot router – As a last resort, reboot your router in case there are issues in its config.
Following the standard networking troubleshooting steps methodically can help track down most connectivity issues with your new Raspberry Pi static IP setup.
Final Thoughts
Getting a static IP configured on a Raspberry Pi may sound intimidating, but as you can see it‘s actually quite straightforward by modifying the dhcpcd.conf file.
With your Pi now having consistent IP addresses, you open up projects around web servers, VPN access, remote management, and more. No more dealing with a dynamic address that changes constantly!
Some additional ideas for building on a static IP:
- Host a Raspberry Pi web server with Apache or Nginx
- Set up OpenVPN for secure remote access
- Configure dynamic DNS for easy remote access
- Attach peripherals like sensors that can be monitored
I hope this guide has demystified the process of assigning static IPs on the Raspberry Pi. Let me know if you have any other networking questions!


