Skip to content
GEEKnodes

Raspberry Pi · Updated on

Set a Static IP on Raspberry Pi OS (Lite and Desktop)

Give your Raspberry Pi a static IP: DHCP reservation on the router or nmcli on Raspberry Pi OS Bookworm and Trixie, and dhcpcd.conf for old systems.

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

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.

The router reserves an IP for the Raspberry Pi by binding its MAC address through DHCP.
The router gives the same IP to the Raspberry Pi’s MAC.
  1. Find the MAC of the interface you use (eth0 for cable, wlan0 for Wi-Fi):
ip link show eth0

It is the value after link/ether.

  1. Open the router’s settings and find a section named something like “DHCP”, “LAN” or “Address reservation”. Each maker puts it somewhere else.
  2. Bind the MAC to the IP you want and save.
  3. 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.

Manual IP diagram with mask, gateway and DNS on a Raspberry Pi connected to the router.
Configure IP, gateway and DNS in the network profile.

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 (/24 equals 255.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:

Output of ifconfig on Raspbian showing the network interface IP

Open the file:

sudo nano /etc/dhcpcd.conf

Scroll to the # Example static IP configuration section:

Commented Example static IP configuration section in dhcpcd.conf

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

Uncommented static IP lines in dhcpcd.conf with interface, IP, router and DNS
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.

Gear

Raspberry Pi 4 (4 GB) Raspberry Pi 4 (2 GB)

Accessibility preferences

Quick profiles

Text and reading

Text size
Default
Line height
Default
Letter spacing
Default
Word spacing
Default

Colour

Motion and orientation

Cursor