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.
/home/pi/bin/ethernet_setup.sh
ifconfig
command arguments (on line 38) to arguments appropriate for your LANchmod 500 /home/pi/bin/ethernet_setup.sh
/etc/systemd/system/ethernet.service
sudo systemctl daemon-reload
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