A Reliable Static IP for Headless Raspberry Pi OS Using dhcpcd.conf
A headless Raspberry Pi that changes its IP address after every reboot breaks SSH access. Here is how to pin a fixed address in dhcpcd.conf, verify it, and avoid common traps.
13 Jul 2025, 12:22 UTC

The reboot that breaks your SSH session
If you run a Raspberry Pi without a monitor or keyboard—headless—you almost certainly reach it over SSH. That works smoothly until the Pi reboots and its IP address changes. Yesterday you connected to 192.168.1.42; today your router hands out 192.168.1.87 and your SSH command times out. The useful takeaway is simple: stop letting the network assign the address by chance and pin it yourself.
On Raspberry Pi OS releases that ship with dhcpcd as the default network manager, the cleanest place to do this is /etc/dhcpcd.conf. You do not need to install extra packages, and the setting survives reboots.
Why dhcpcd is the right place to intervene
DHCP (Dynamic Host Configuration Protocol) is the service your router uses to hand out IP addresses automatically. Each handout is a lease that can expire and change. A daemon is a background service; on Raspberry Pi OS, dhcpcd is the daemon that asks the router for a lease and configures the network interfaces—the wired port (eth0) or the wireless adapter (wlan0).
Because dhcpcd reads /etc/dhcpcd.conf at boot, a static block placed there is applied every time the Pi starts. On Raspberry Pi OS Lite, NetworkManager is not installed by default, so dhcpcd is the only manager you need to worry about. If you are running a desktop variant or have installed NetworkManager yourself, editing dhcpcd.conf can create duplicate configuration and unpredictable behavior; in that case, use the manager that is actually active.
Worked example: pinning eth0 to a fixed address
Open the configuration file on the Pi itself. You need sudo because the file is owned by root.
sudo nano /etc/dhcpcd.conf
Add a separate block for the interface you want to control. Each interface needs its own block; do not merge eth0 and wlan0 into one.
interface eth0
static ip_address=192.168.1.50/24
static routers=192.168.1.1
Replace the placeholders with values that match your network:
192.168.1.50is the address you want the Pi to keep./24is the subnet mask in CIDR notation, common for home networks.192.168.1.1is your gateway—usually the router’s LAN address.
If you also want a fixed address on Wi-Fi, add a second block for wlan0 with its own static lines. Save the file, then restart the daemon so the change takes effect immediately without a reboot:
sudo systemctl restart dhcpcd.service
Risk: if you are connected over SSH and you enter a wrong subnet or gateway, you can lock yourself out. Have console access or a second way to reach the Pi before you apply the change.
Verify, trade-offs, and how to back out
Check that the interface actually received the address:
ip addr show eth0
Look for an inet line that matches 192.168.1.50/24. Next, confirm the Pi can reach the rest of the network through the gateway:
ping 192.168.1.1
If replies arrive, routing is functional. For deeper diagnostics, inspect the daemon log:
sudo cat /var/log/dhcpcd.log
The main limitation is conflict. If your router’s DHCP pool already includes 192.168.1.50, the router may eventually assign that same address to another device, causing an IP clash and intermittent connectivity. To avoid this, either choose an address outside the DHCP range or create a DHCP reservation on the router so the same address is always tied to the Pi’s MAC address.
If the change causes problems, roll back by commenting out the static block with # and restarting the service:
# interface eth0
# static ip_address=192.168.1.50/24
# static routers=192.168.1.1
sudo systemctl restart dhcpcd.service
Before you reboot
Check your router’s DHCP range first, pick an address outside that range, and keep the gateway accurate. Then apply the block, restart dhcpcd, and verify with ip addr and a gateway ping. Once the address holds across a reboot, your headless Pi becomes a stable target for SSH, file transfers, and automation.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.