Table of Contents
KEY TAKEAWAYS
- A static IP ensures the Raspberry Pi always has the same network address for remote access
- Configure static IP in
/etc/dhcpcd.confby setting the interface, IP address, router, and DNS - Choose an IP address outside the DHCP range of your router to avoid address conflicts
- Restart the networking service or reboot for the static IP configuration to take effect
1. Information about current Network
To 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 defaultBy 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.109 metric 100Make 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.2. Retrieve current DNS Server
Next, let us also retrieve the current DNS server.We can do this by opening up the “resolv.conf” configuration file by running the following command.sudo nano /etc/resolv.confFrom this command, you should see the lines of text below.
# Generated by resolvconf nameserver 8.8.8.8Make a note of the IP next to “
nameserver“. This will define the name server in our next few steps.3. Configure static IP on Raspberry Pi in dhcpcd.conf file
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.confWithin this file, enter the following lines.
interface <NETWORK> static ip_address=<STATICIP>/24 static routers=<ROUTERIP> static domain_name_servers=<DNSIP>First, you have to decide if you want to set the static IP for your “
eth0” (Ethernet) connector or you “wlan0” (WiFi) connection. Decide which one you want and replace “<NETWORK>” with it.Make the following changes:– 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 in step 1 of this tutorial– Finally, replace “<DNSIP>” with the IP of the domain name server you want to utilize. This address is either the IP you got in step 2 of this tutorial or another one such as Googles “8.8.8.8” or CloudFlare’s “1.1.1.1“.Example:interface eth0 static ip_address= 192.168.0.109 static routers= 192.168.0.1 static domain_name_servers= 8.8.8.8Now save the file by pressing CTRL + X then Y followed by ENTER.Now that we have modified our Raspberry Pi’s DHCP configuration file so that we utilize a static IP address, we need to go ahead and restart the Raspberry Pi.
sudo reboot
4. Test the Configuration
Once your Raspberry Pi has finished restarting you now should be able to connect using the IP address you specified.If you are connecting locally and want to verify the static IP address set correctly, you can do that by running the following command.hostname -IFrom this command, you should now be able to see your new static IP address. If it is the IP that you expected, then you have now successfully set up a static IP address on your Raspberry Pi.I hope that this Raspberry Pi static IP tutorial has helped achieve your task. If you have any feedback on this tutorial, then please don’t hesitate to leave a comment.

Vivek Bhageria — Lead Firmware R&D Engineer, 12+ years. Ex-Bosch (automotive powertrain), MusicTribe (real-time audio), medical devices. M.Tech BITS Pilani. I write at NerdyElectronics — practical, register-level embedded systems for engineers who want to understand what’s actually happening under the hood.





