Raspberry Pi Static IP Guide
Raspberry Pi Static IP Configuration: A Technical Investigation into Network Persistence
Master Raspberry Pi static IP setup with nmcli and dhcpcd methods. Step-by-step guide for stable headless network configuration.
The Shifting Landscape of Raspberry Pi Networking
For years, the Raspberry Pi community operated under a shared assumption: editing /etc/dhcpcd.conf was the definitive path to network permanence. That assumption has fractured. Recent iterations of Raspberry Pi OS have introduced NetworkManager as the default networking stack, silently overriding legacy configuration files and leaving users with unresponsive devices and frustrated troubleshooting sessions. This investigation examines the current technical realities of assigning a static IP address to a Raspberry Pi, separating enduring principles from deprecated practices.
Understanding the Core Requirement
A static IP address ensures a Raspberry Pi maintains a consistent network identifier across reboots and power cycles. This stability proves essential for headless deployments, home automation hubs, network-attached storage, or any scenario where remote access depends on predictable addressing. Without it, DHCP-assigned addresses may shift, breaking SSH connections, service discovery, and automated scripts.
Prerequisites Before Configuration
Before modifying any system files, gather three critical network parameters:
- Current IP address: Execute
hostname -Ito identify the Pi's present dynamic address. - Default gateway: Run
ip r | grep defaultto locate your router's address, typically192.168.1.1or similar. - Active connection name: Use
nmcli connection showto list NetworkManager profiles; Wi-Fi connections often match the SSID, while Ethernet may appear as "Wired connection 1".
Select a static IP outside your router's DHCP allocation range—commonly between .2 and .99 or .201 and .254—to prevent address conflicts.
Method One: NetworkManager via nmcli (Modern Approach)
For Raspberry Pi OS Bookworm and later releases, NetworkManager governs network interfaces. The nmcli command-line utility provides direct, reliable control.
Step-by-Step nmcli Configuration
Modify the connection profile with your chosen parameters:
sudo nmcli connection modify "YourConnectionName" \ ipv4.addresses 192.168.1.155/24 \ ipv4.gateway 192.168.1.1 \ ipv4.dns 192.168.1.1 \ ipv4.method manualReplace
YourConnectionNamewith the profile identified earlier. Adjust addresses to match your network topology. The/24suffix denotes a standard subnet mask (255.255.255.0).Apply changes immediately by restarting the connection:
sudo nmcli connection down "YourConnectionName" sudo nmcli connection up "YourConnectionName"Verify persistence with
hostname -I. The output should display your newly assigned static address.
This method functions identically for Wi-Fi and Ethernet interfaces and remains effective in headless environments where graphical tools are unavailable.
Method Two: dhcpcd.conf (Legacy Compatibility)
On earlier Raspberry Pi OS versions—or systems where NetworkManager has been disabled—the dhcpcd daemon remains operational. Configuration occurs through /etc/dhcpcd.conf.
Implementing dhcpcd Static Assignment
Append the following block to the configuration file, customizing values for your environment:
interface eth0
static ip_address=192.168.1.155/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
interface wlan0
static ip_address=192.168.1.156/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
Save the file and reboot with sudo reboot. The Pi will adopt the specified addresses upon restart.
Interface Prioritization
When both Ethernet and Wi-Fi are active, assign metric values to control routing precedence. Higher metrics receive priority:
interface eth0
metric 300
static ip_address=192.168.1.155/24
interface wlan0
metric 200
Headless Deployment Strategies
Configuring a static IP before first boot—critical for headless setups—requires direct file manipulation on the SD card.
Pre-Boot File Editing
Mount the SD card's root partition on another Linux system. Edit /etc/dhcpcd.conf as described above. Then, create an empty file named ssh in the boot partition to enable remote access on first startup.
cmdline.txt Alternative
For advanced users, appending an ip= parameter to /boot/cmdline.txt forces early network initialization:
ip=192.168.1.155::192.168.1.1:255.255.255.0:raspberrypi:eth0:off
This syntax specifies IP address, gateway, netmask, hostname, interface, and DHCP behavior. Ensure the entry appears on a single line, separated by spaces from preceding parameters.
Link-Local Fallback
When no DHCP server is present, Raspberry Pi OS assigns a link-local address (169.254.x.x). Connect the Pi directly to a computer via Ethernet, configure the computer's interface within the same subnet, then access the Pi using ssh pi@raspberrypi.local or a network scanner like arp-scan.
Verification and Troubleshooting
After configuration, confirm network behavior with these diagnostics:
hostname -Idisplays all assigned addresses.ping -c 4 8.8.8.8tests external connectivity.nmcli connection show --activelists active NetworkManager profiles and their settings.
If the static IP fails to apply, check for conflicting configurations: NetworkManager and dhcpcd should not manage the same interface simultaneously. Review system logs with journalctl -u NetworkManager or journalctl -u dhcpcd for error messages.
Frequently Asked Questions
Q: Why doesn't editing dhcpcd.conf work on my new Raspberry Pi?
A: Raspberry Pi OS Bookworm and later versions use NetworkManager by default, which supersedes dhcpcd. Use nmcli commands or disable NetworkManager to restore dhcpcd functionality.
Q: Can I assign static IPs to both Wi-Fi and Ethernet simultaneously?
A: Yes. Configure each interface separately using either nmcli or dhcpcd.conf. Assign distinct IP addresses within your subnet to avoid conflicts.
Q: How do I revert to DHCP after setting a static IP?
A: For nmcli, run sudo nmcli connection modify "YourConnectionName" ipv4.method auto. For dhcpcd.conf, remove the static configuration blocks. Restart the connection or reboot to apply changes.
Q: What if my static IP causes network conflicts?
A: Ensure the chosen address falls outside your router's DHCP pool. Use arp-scan or your router's admin interface to identify active addresses before assignment.
Q: Is avahi-daemon a viable alternative to static IPs?
A: Yes. Avahi enables hostname-based discovery via .local domains (e.g., raspberrypi.local), reducing dependence on fixed addresses. However, static IPs remain preferable for services requiring explicit address references or firewall rules.