10

I am trying to set up a static IP lease on Raspberry Pi 5. The /etc/dhcpcd.conf file does not exist and dhcpcd is not installed. Following the latest guides does not work. I ideally don't need to use DHCP, but if there's a way that works with either option I'm open to suggestions.

I'm starting to wonder whether the Pi 5 been set up correctly.

I am unable to install any packages since I do not have internet. Is there any long lasting method that could work?

Milliways
  • 62,573
  • 32
  • 113
  • 225
Joe Moore
  • 211
  • 1
  • 2
  • 7

3 Answers3

8

I see you've found an answer, so this is just FYI:

The people who run the RPi manufacturing operation decided to replace dhcpcd with nmcli as the default DHCP client program for the bookworm release. However, as I understand it, dhcpcd remains in the distribution (or certainly available for the price of a sudo apt install dhcpcd), so you can continue to use it - at least for a while.

And since this is an "FYI" kind of answer, I'll opine that dhcpcd is a pretty good DHCP client. It's still actively maintained by Roy Marples, and recently upgraded to ver 10. I feel that part of the reason that dhcpcd fell out of favor with the RPi manufacturing consortium was that they (and Debian) let it languish... they decided to stick with version 8 instead of following the upstream releases. Why?... I don't know, you'll have to ask them.

If you decide you do want to stick with dhcpcd, you have a couple of options:

  1. Stick with the old-ish version 8.1.2.

  2. If you want the latest version (ver 10) you'll need to build it from source.

Finally, wrt to your comment, "I'm starting to wonder whether the Pi 5 been set up correctly.". Yeah - you're not alone. :)

Seamus
  • 23,558
  • 5
  • 42
  • 83
7

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:

  1. Use /etc/network/interfaces
  2. Use nmcli, or nmtui for NetworkManager
  3. Use the GUI for NetworkManager (from your desktop)
  4. 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.:

  1. 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.

  2. 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.

Seamus
  • 23,558
  • 5
  • 42
  • 83
Ben Bird
  • 202
  • 1
  • 4
7

The first Raspberry Pi OS that supports Raspberry Pi 5 manages the network settings by default with NetworkManager, as per https://www.raspberrypi.com/news/bookworm-the-new-version-of-raspberry-pi-os/

To set a static IP of 192.168.1.50:

$ nmcli connection modify help
[...]
Examples:
nmcli con mod em1-1 ipv4.method manual ipv4.addr "192.168.1.2/24, 10.10.1.5/8"

$ nmcli con show NAME UUID TYPE DEVICE Wired connection 1 aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa ethernet eth0
MyWiFi bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb wifi wlan0
lo cccccccc-cccc-cccc-cccc-cccccccccccc loopback lo

$ nmcli con show "Wired connection 1" | tee original_network_settings.txt

$ sudo nmcli con mod "Wired connection 1" ipv4.method manual ipv4.addr 192.168.1.50/24

$ sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1 ipv4.dns 192.168.1.1

$ sudo nmcli device reapply eth0

aleb
  • 173
  • 5