0

I am struggling getting my rPi to get a fixed IP. I have this /etc/dhcpcd.conf, but that doesn't seem to do anything:

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

Allow users of this group to interact with dhcpcd via the control socket.

#controlgroup wheel

Inform the DHCP server of our hostname for DDNS.

hostname

Use the hardware address of the interface for the Client ID.

clientid

or

Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.

Some non-RFC compliant DHCP servers do not reply with this set.

In this case, comment out duid and enable clientid above.

#duid

Persist interface configuration when dhcpcd exits.

persistent

Rapid commit support.

Safe to enable by default because it requires the equivalent option set

on the server to actually work.

option rapid_commit

A list of options to request from the DHCP server.

option domain_name_servers, domain_name, domain_search, host_name option classless_static_routes

Respect the network MTU. This is applied to DHCP routes.

option interface_mtu

Most distributions have NTP support.

#option ntp_servers

A ServerID is required by RFC2131.

require dhcp_server_identifier

Generate SLAAC address using the Hardware Address of the interface

#slaac hwaddr

OR generate Stable Private IPv6 Addresses based from the DUID

slaac private

eth0 is our internal net

interface eth0 static ip_address=192.168.250.10/24 static routers=192.168.250.1

After a reboot, this is my IP setup:

pi@raspberrypi:/etc/systemd/network$ ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:ff:b7:e5 brd ff:ff:ff:ff:ff:ff
    inet 169.254.25.116/16 brd 169.254.255.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ba27:ebff:feff:b7e5/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:aa:e2:b0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.3.233/22 brd 192.168.3.255 scope global dynamic noprefixroute wlan0
       valid_lft 690622sec preferred_lft 604222sec
    inet6 fe80::ba27:ebff:feaa:e2b0/64 scope link 
       valid_lft forever preferred_lft forever

Then, when looking for more info on this, I see that "under systemd, the network may be configured" using /etc/systemd/network instead. But, when I read those lines correctly, it want an en* interface, but I have an eth0. Also, what does "may be configured" mean? Either it does it, or it doesn't, right?

Update when I manually set the interface with

pi@raspberrypi:~$ sudo ifconfig eth0 192.168.250.10
pi@raspberrypi:~$ sudo route add -net 192.168.250.0/24 eth0

I have the setup I want (except for some stray route to 169.254.0.0).

So, how can I configure my network interfaces (from the command line) on Debian 11 running on a Raspberry Pi 3 model B?

  • WRT en* vs. eth* (or eth0), these are just different labels an ethernet interface can end up with, you should use what is appropriate (ie., eth0). WRT systemd and Debian, though, beware that RpiOS differs from Debian in that by default it uses dhcpcd, and not systemd's own facilites. WRT "your internal network", to make sure: The other end of the cable is plugged into a DHCP router, right? If not you should explain what it is. – goldilocks Nov 29 '22 at 14:29
  • Finally, WRT static addresses, presuming DHCP is being used: 1) Assigning yourself one does not mean the router will accept it, which is why 2) You should use request not static, see https://raspberrypi.stackexchange.com/questions/37920/how-do-i-set-up-networking-wifi-static-ip-address-on-raspbian-raspberry-pi-os (if you find a solution there, please leave a comment so this can be closed as a duplicate). – goldilocks Nov 29 '22 at 14:29
  • @goldilocks there is no DHCP router. The "internal net" is a switch with three devices, each with a fixed IP address, of which the rPi is one. – Bart Friederichs Nov 29 '22 at 14:32
  • This question is misleading. You have omitted vital details. You have a wireless network on a different subnet. You are attempting to use a different networking service and mixing conflicting information. – Milliways Nov 29 '22 at 21:12
  • @Milliways how is that misleading, if I post all that information? I was attempting all kinds of things, because I couldn't get it working. And I supplied all my tries in the question. I think you can honestly say that networking on the Pi (Debian?) is messy, with many unused files, duplicate configuration, etc. Kind of like the sound situation on most Linuxes. – Bart Friederichs Nov 30 '22 at 08:08
  • My principal objection is what you omitted from your question. Networking on the Pi is just standard Linux networking; there is nothing special. Linux has > than 6 common networking systems - I use 3 BUT you have to pick ONE and stick to it NOT mix incompatible systems. If you are going to use dhcpcd systemd.networkd documentation is irrelevant. – Milliways Nov 30 '22 at 08:42

2 Answers2

1

there is no DHCP router. The "internal net" is a switch with three devices, each with a fixed IP address, of which the rPi is one.

If there's no DHCP, using a DHCP client to set up networking seems inappropriate, doesn't it? To be fair, you likely could configure dhcpcd to deal with this, but it is so simple otherwise it is probably not worth the effort, or the potential complications.

So I recommend removing the interface eth0 block in dhcpcd.conf and replacing it with:

denyinterfaces eth0

This way, dhcpcd will ignore it.

Activating the interface on a network of the sort you describe is, again, very simple:

sudo ip link set eth0 up
sudo ip addr add 192.168.250.10/24 dev eth0

The routing then should be configured automatically; check the output of ip route, which should include:

192.168.250.0/24 dev eth0 proto kernel scope link src 192.168.250.10

If not, try:

sudo ip route add 192.168.250.0/24 via 192.168.250.10 dev eth0

To enable this at boot, put the those first two commands into a text file with a shebang at the top:

#!/bin/sh

ip link set eth0 up ip addr add 192.168.250.10/24 dev eth0

Notice, no sudo there. Put this in, eg. /etc/eth0net/interface-up.sh, make it owned root and executable:

sudo chown -R root.root /etc/eth0net
sudo chmod 755 /etc/eth0net/interface-up.sh

Create a file /etc/systemd/system/eth0net.service; you will need superuser permission. In that:

[Unit]
Description=Local ethernet link
Requires=local-fs.service

[Service] Type=oneshot RemainAfterExit=yes StandardInput=null ExecStart=/etc/eth0net/interface-up.sh

[Install] WantedBy=default.target

And enable it with systemctl enable eth0net.service. You can test run this before reboot with systemctl start eth0net. To check systemctl status eth0net; the output should include active (exited).

goldilocks
  • 58,859
  • 17
  • 112
  • 227
  • I agree on the "If there's no DHCP, using a DHCP client to set up networking seems inappropriate, doesn't it?" I just never realised that dhcpcd would talk to a DHCP router if you supply a static address. When setting a static/fixed address in other Linuxes (e.g. NetworkManager), this always worked fine. TIL. – Bart Friederichs Nov 30 '22 at 08:10
  • I tried to add the denyinterfaces in dhcpcd.conf, but the device is still being configured by dhcpcd. I am using predictive interfaces, so I have denyinterfaces enx3x.... – Bart Friederichs Nov 30 '22 at 13:27
  • There's a mistake, because denyinterfaces absolutely does work, unless there is something contradictory in the conf or some other network software running (are you sure it is dhcpcd?) -- you might look through /etc/network/* for references to the ethernet interface. But first try denyinterfaces e*, that should cover pretty much anything ethernet but not anything else (unless you are creating virtual interfaces with names beginning with e etc). Not sure if your enx3x was supposed to be literal, but that won't match anything. The pattern is a shell glob and x is not a wildcard. – goldilocks Nov 30 '22 at 14:42
  • "never realised that dhcpcd would talk to a DHCP router if you supply a static address'" -> The man page does say it "will not attempt to obtain a lease and will just use the value for the address with an infinite lease time", so it should work. Right now though, it is just giving you a link local address (169.254.25.116); that can be disabled with noipv4ll. BTW, this is verbatim the methodology used by me to do much the same thing. If possible, you should try shutting dhcpcd down (along with the other network access it provides), and just go through the steps here to see what happens. – goldilocks Nov 30 '22 at 14:54
  • thanks for your help. I decided to ditch dhcpcd eventually. I got everything working how I want it, using systemd-networkd (see also my answer). – Bart Friederichs Nov 30 '22 at 16:35
1

I decided to ditch dhcpcd and use systemd-networkd instead. Steps to do so:

  1. Disable dhcpcd: systemctl disable dhcpcd

  2. Enable systemd-networkd: systemctl enable systemd-networkd

  3. Disable wpa_supplicant: systemctl disable wpa_supplicant

  4. Create .link files to create predictable network names based on mac, example 20-usbnic.link:

    [Match]
    MACAddress=b8:27:eb:ff:b7:e5
    

    [Link] Description=USB NIC Name=usbnic

  5. Create .network files to set DHCP or fixed address, example:

    [Match]
    Name=usbnic
    

    [Network] Address=192.168.250.10/24

  6. Create /etc/wpa_supplicant/wpa_supplicant-wlan0.conf to use interface-based wpa_supplicant (see also here https://unix.stackexchange.com/questions/453329/where-is-my-etc-wpa-supplicant-conf-on-systemd)

  7. Enable wpa_supplicant on that interface: systemctl enable wpa_supplicant@wlan0

  8. Reboot for all changes to take effect