When I connect a USB-to-Ethernet adapter (that has been previously used), I receive a MAC address, and then if there's something connected on the other end I receive also an IP address (192.168.1.1 in my case, configured in static in NetworkManager). On the other end there are various instruments that wait for the DHCP server running on that PC to give them an IP.
The problem is that the DHCP server refuses to start if the subnet is not found, so it cannot be launched before the connection is up. How can I do systemctl restart isc-dhcp-server.service
after I receive the IP 192.168.1.1 from NetworkManager ?
I thought of using a udev rule with ATTR{address}=="f0:1f:af:3d:6c:e7" RUN+="systemctl restart isc-dhcp-server.service"
but it runs before the IP is assigned. Is there a udev option I can use or do I have to use another method via systemd or NetworkManager or other ?
UDEV triggering a systemd service is the way to do this.
you can match your usb adapter by usb id , its too late when you can see a mac address.
this post has the instructions
https://unix.stackexchange.com/questions/229987/udev-rule-to-match-any-usb-storage-device
Your system is configured with systemd .
So one solution is to add a dependency between
isc-dhcp-server
and the usb device .ps 6c & e7 are the last 2 bytes of your mac from you usb device
you must have something like
isc-dhcp-server
and add these lines
reboot
check status and configuration of
isc-dhcp-server
by running these commandsFinally spent some time on this problem and solved it with a script I named
restart-dhcpd.sh
and placed in/etc/NetworkManager/dispatcher.d/
. (Note: you may need tosystemctl restart network-manager.service
and/orsystemctl daemon-reload
afterwards):