Raspberry Pi

Ethernet : Reliable Initialization

Bernard Karmilowicz

Problem: The Ethernet hardware on some Raspberry Pi boards is inconsistently configured during boot.

Solution: A short-lived systemd service that gently coaxes the Ethernet hardware to ready itself for configuration, and then performs the configuration.

The Ethernet interface on two of my Raspberry Pi (3B+ and 4B) boards was not consistently configured during boot. It appears the hardware is not always up before the systemd network scripts expect the interface to be available. A symptom of the problem is no carrier being detected by the interface (eth0), which results in failed attempts to configure eth0 (by issuing an ifconfig command) after booting.

A script and a corresponding systemd service unit-file solve this problem of eth0 not being consistently configured when a Raspberry Pi boots. Follow these instructions for their use. The script is written with the expectation eth0 configuration is static.

  1. Copy the script to /home/pi/bin/ethernet_setup.sh
  2. Change the script's ifconfig command arguments (on line 38) to arguments appropriate for your LAN
  3. chmod 500 /home/pi/bin/ethernet_setup.sh
  4. Copy the service unit-file to /etc/systemd/system/ethernet.service
  5. Tell systemd to reconfigure itself, thereby incorporating ethernet.service, by issuing the command:
    sudo systemctl daemon-reload
  6. Tell systemd to start ethernet.service automatically when booting, by issuing the command:
    sudo systemctl enable ethernet.service

After rebooting; You can confirm ethernet.service was used by systemd to run the ethernet_setup.sh script during boot, by issuing either of these two commands:

journalctl -u ethernet.service
systemctl status ethernet.service

background image