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?

Bart Friederichs
  • 273
  • 2
  • 10

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
  • 60,325
  • 17
  • 117
  • 234
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

Bart Friederichs
  • 273
  • 2
  • 10