How to Set a Static IP Address on Raspberry Pi
Assigning a static IP address to a Raspberry Pi ensures it maintains the same network location every time it boots, which is essential for hosting servers, SSH access, or running home automation. This guide covers the two most reliable methods for locking in your Pi’s IP address: configuring your local router’s DHCP reservation settings or directly editing the configuration files within the Raspberry Pi OS.
Why You Need a Static IP
By default, routers assign dynamic IP addresses to devices using DHCP (Dynamic Host Configuration Protocol). This means your Raspberry Pi’s IP address can change whenever the router reboots or the lease expires. If you are running a headless setup, a media server like Plex, or a Pi-hole, a shifting IP address will break your connections and require you to hunt for the new address every time.
Method 1: Router DHCP Reservation (Recommended)
The cleanest way to assign a static IP is through your router. This prevents IP conflicts by telling the router to always reserve a specific IP address for your Raspberry Pi’s unique MAC address.
- Log into your router’s web admin portal by typing its IP address
(usually
192.168.1.1or192.168.0.1) into a web browser. - Locate the DHCP Server, Static Lease, or IP Reservation settings page.
- Find your Raspberry Pi in the list of connected devices.
- Note its MAC address (a 12-character alphanumeric
code like
aa:bb:cc:dd:ee:ff). - Add a new reservation rule linking that MAC address to your desired static IP address. Ensure the chosen IP is outside the main pool of dynamically assigned addresses to avoid future overlaps.
Method 2: Configuring Raspberry Pi OS (Bookworm and Newer)
If you are using the latest Raspberry Pi OS (Bookworm), the operating system handles networking via NetworkManager. You can easily set a static IP using the built-in terminal tool.
- Open a terminal window on your Raspberry Pi or connect via SSH.
- Run the NetworkManager text user interface tool:
sudo nmtui - Use the arrow keys to select Edit a connection and press Enter.
- Select your active connection (usually
Wired connection 1for Ethernet or your Wi-Fi network name) and choose Edit. - Scroll down to IPv4 CONFIGURATION, change it from
<Automatic>to<Manual>, and select<Show>. - Next to Addresses, select
<Add>and type your desired static IP followed by the network prefix (for example,192.168.1.100/24). - Enter your router’s IP address in the Gateway field
and your preferred DNS servers (such as
8.8.8.8for Google DNS). - Scroll down, select
<OK>, and exit the utility. - Restart the network connection to apply changes:
sudo nmcli connection up [Connection Name]
Method 3: Configuring Older Raspberry Pi OS (Bullseye and Earlier)
Legacy versions of Raspberry Pi OS rely on dhcpcd to
manage network interfaces. If you are running an older operating system
version, you must modify the configuration file manually.
- Open the configuration file in the nano text editor:
sudo nano /etc/dhcpcd.conf - Scroll to the bottom of the file and append the following lines,
substituting
eth0for Ethernet orwlan0for Wi-Fi depending on your connection type:
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
- Save and close the file by pressing
Ctrl+O,Enter, and thenCtrl+X. - Reboot your Raspberry Pi to finalize the network adjustment:
sudo reboot
Verifying the Setup
Once your Raspberry Pi reboots, you can confirm that the network
settings applied successfully. Open the terminal and type
hostname -I. The output should display the exact static IP
address you configured, confirming your Raspberry Pi is now permanently
reachable at that destination.