If you have a Pi 5, it will have the 'bookworm' version of Debian installed. dhcpcd was the default "network manager" software in the 'bullseye' release, but dhcpcd was replaced by a package called 'NetworkManager' in the 'bookworm' release.
Raspberry Pi OS is largely the same as Debian. This guide was written for Debian, and was helpful for me. The Debian documentation is also available, but is in multiple locations; e.g.: NetworkConfiguration, WiFi HowToUse. Both sources show several different methods for accomplishing a static IP setup:
- Use
/etc/network/interfaces
- Use
nmcli, or nmtui for NetworkManager
- Use the GUI for NetworkManager (from your desktop)
- Use
systemd-networkd
AFAIK, unlike dhcpcd, none of the methods above require installation of "new" packages.
Here's one way to do it using "Method 1". Edit the following example as needed, and place in /etc/network/interfaces or a separate file in /etc/network/interfaces.d/. See man interfaces for details.:
auto eth0
iface eth0 inet static # note keyword 'static'
address 192.168.1.100 # Your desired static IP address
netmask 255.255.255.0 # Your subnet mask
gateway 192.168.1.1 # Your gateway (router) IP address
# dns-nameserver 8.8.8.8 # DNS add multiple servers (see note 2 below)
If your network interface is wifi, you'll need to change this a bit:
auto wlan0
iface wlan0 inet static
wpa-ssid ESSID # Your wifi server's ESSID
wpa-psk your password # Your WPA password
address 192.168.1.100 # Your desired static IP address
netmask 255.255.255.0 # Your subnet mask
gateway 192.168.1.1 # Your gateway (router) IP address
# dns-nameserver 8.8.8.8 # DNS add multiple servers (see note 2 below)
And finally, if you prefer to use DHCP for automatic network configuration, your interfaces file will look like this:
allow-hotplug wlan0
iface wlan0 inet dhcp # note keyword 'dhcp'
wpa-ssid ESSID # Your wifi server's ESSID
wpa-psk your password # Your WPA password
You may wonder, "how does this work... what happened to the default NetworkManager?" The explanation is found in /usr/share/doc/network-manager/README.Debian:
Network devices which are configured in /etc/network/interfaces will typically be managed by ifupdown. NetworkManager respects such a configuration and will ignore those devices and mark them as "unmanaged".
Alternatively, use "Method 2" - nmcli or nmtui from NetworkManager. To conserve space, the nmcli option is shown here (but nmtui is easier to use):
$ sudo nmcli con mod "preconfigured" ipv4.addresses "192.168.1.99/24" ipv4.gateway "192.168.1.1" ipv4.dns "8.8.8.8" ipv4.method manual
Notes on the nmcli command above:
- "preconfigured": This is the name of the default "connection file" assigned for use by Raspberry Pi; located at:
/etc/NetworkManager/system-connections/preconfigured.nmconnection
- "192.168.1.99/24" - your fixed IP addr (CIDR format)
- don't spend much time looking for logic in NM - there's very little to be found there.
N.B.:
Using static IPs is not generally considered "best practice". You should also be aware that (depending on your local network configuration), you will most likely need to make changes to your "router/DHCP server/gateway" to achieve reliable results - regardless of which of the methods above you use.
WRT the dns-nameserver line: This may be deprecated from recent distributions. It is not even mentioned in man interfaces. Refer instead to the Debian Networking Guide.