If you use the Raspberry Pi as a server (Pi-hole, OctoPrint, Home Assistant, a NAS…) you want it to always have the same IP address, so you do not have to look for it each time the router changes it. There are two ways to do it, and this guide shows both for Raspberry Pi OS Bookworm and Trixie, plus the old dhcpcd.conf method for anyone still on a pre-2023 system.
Before you start
- Access to a terminal on the Raspberry, locally or over SSH. If you change the IP over SSH, the session will drop and you will have to reconnect with the new one.
- Know your system version:
cat /etc/os-release
- Know your network details. This command shows the current IP and mask (for example
192.168.1.40/24):
ip -4 addr show
And this one the gateway (the router), shown after default via:
ip route
Option 1: DHCP reservation on the router (recommended)
The official Raspberry Pi documentation recommends this over fixing the IP on the Raspberry itself, because a configuration mistake on the device can leave you without a connection. It is called “DHCP reservation” or “static lease”: you tell the router to always give the same IP to the Raspberry’s MAC address.

- Find the MAC of the interface you use (
eth0for cable,wlan0for Wi-Fi):
ip link show eth0
It is the value after link/ether.
- Open the router’s settings and find a section named something like “DHCP”, “LAN” or “Address reservation”. Each maker puts it somewhere else.
- Bind the MAC to the IP you want and save.
- Restart the Raspberry’s network, or the Raspberry itself, so it requests an address again.
Extra benefit: if you change router or network, the Raspberry keeps working with DHCP without touching anything.
Option 2: static IP with nmcli (Bookworm and Trixie)
Since Bookworm, Raspberry Pi OS manages the network with NetworkManager, and /etc/dhcpcd.conf is no longer used. The terminal tool is nmcli.

Pick an IP outside the router’s DHCP range (for example, if the router hands out .100 to .200, use .50) that no other device uses.
1. Find the connection name
nmcli connection show
You will see a list with each connection’s name and device. Depending on how the system was set up, the wired one may be called Wired connection 1 or start with netplan-, and the Wi-Fi created by Raspberry Pi Imager is usually preconfigured or netplan-wlan0-…. Copy the exact name.
2. Set IP, gateway and DNS
Replace the connection name and values with yours:
sudo nmcli connection modify "Wired connection 1" \
ipv4.method manual \
ipv4.addresses 192.168.1.50/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "192.168.1.1 1.1.1.1"
ipv4.addresses: the IP with the mask in CIDR format (/24equals255.255.255.0).ipv4.gateway: the router’s IP.ipv4.dns: one or more DNS servers separated by spaces and quoted.
3. Apply the changes
Changes are saved in the profile but not applied until you reactivate the connection:
sudo nmcli connection up "Wired connection 1"
If you prefer a menu to commands, sudo nmtui does the same under Edit a connection.
Go back to DHCP
sudo nmcli connection modify "Wired connection 1" \
ipv4.method auto ipv4.addresses "" ipv4.gateway "" ipv4.dns ""
sudo nmcli connection up "Wired connection 1"
Old systems: dhcpcd.conf (Bullseye and earlier)
Only if your Raspberry still runs Raspberry Pi OS Bullseye, Buster or the old Raspbian was the static IP set in /etc/dhcpcd.conf. On those systems, network info was shown with ifconfig:

Open the file:
sudo nano /etc/dhcpcd.conf
Scroll to the # Example static IP configuration section:

Then uncomment and adapt the lines, using eth0 for cable or wlan0 for Wi-Fi:

interface eth0
static ip_address=192.168.1.50/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 1.1.1.1
Save with Ctrl+O, exit with Ctrl+X and reboot with sudo reboot. These systems no longer receive updates, so consider installing the current version.
Check that it works
ip -4 addr show
ip route
ping -c 3 1.1.1.1
ping -c 3 raspberrypi.com
The first line should show your new IP; ip route should list the right router after default via. If ping to 1.1.1.1 works but to raspberrypi.com does not, the problem is DNS.
Common problems
You lost the SSH connection. Normal when changing the IP: reconnect with the new address. If it does not respond, connect a monitor or check its IP on the router.
Error: unknown connection. The name does not match. Copy the exact name from nmcli connection show, quoted if it has spaces.
IP conflict: the network comes and goes. Another device has the same address or the router is handing it out via DHCP. Pick an IP outside the DHCP range or use the router reservation.
Local network works but no internet. Gateway or DNS are wrong. Check ipv4.gateway and ipv4.dns.
You edited dhcpcd.conf on Bookworm and nothing happens. Bookworm and Trixie do not use that file. Use nmcli or nmtui.
Related
- Set up Wi-Fi on Raspberry Pi OS Lite
- Enable SSH on a Raspberry Pi without monitor or keyboard
- Types of computer network connections
- Control the Ender 3 remotely with OctoPrint



