3

I have an embedded device that will connect with systemd-networkd to a DHCP server if connected to the local network and will fall back to being a DHCP server if not. I didn't implement it yet but plan using the answer described here https://unix.stackexchange.com/a/309046/114497 .

This answer points to use a script that will be started on boot. I was wondering what if the user unplugs the network cable and connects it to a PC at runtime, he'd need to restart the board for the script to start. So the question is: is there a way to start a script when there's an interface change with systemd?

PS: I tried using networkd-dispatcher without success. I tried restarting the systemd-networkd service, unplug the ethernet cable but the script I wrote located in /usr/lib/networkd-dispatcher is not executed.

  • Ethernet connect/disconnect events are availabinle via NETLINK, see e.g. here (answer proposes to use ifplugd). I have no idea if systemd listens to NETLINK events for network interfaces. – dirkt May 31 '19 at 17:25

2 Answers2

0

This answer explain what can be done with systemd when network changes...

There are many alternative solution, but a direct simple solution only with systemd is not implemented as of 06/2019

intika
  • 14,406
0

You could adapt my net-o-matic script, which currently watches for DOWN to look for UP. Start it from an @reboot root crontab entry.

I've written a bash script to help with this: https://github.com/waltinator/net-o-matic It watches the connection, and when the connection drops, does a user-specified thing to try to reconnect.

waltinator
  • 4,865