I have a portable linux box running ubuntu 16.04 with a single network interface, which when plugged in to a network should make sure that there is a DHCP server on that network. Two cases:
(a) if there is DHCP already running on the network, the box should just get an ip there.
(b) if no DHCP exists on the network, the box should start a DHCP server.
In the case of (b), I have dnsmasq running. However, I would like the system to automatically detect (a) or (b) and start the dnsmasq service depending on the outcome.
So far my approach was to setup /etc/network/interfaces for eth0 as static (as a basis for the internally provided DHCP) and eth0:1 as dhcp configured. I've tried finding something that would start/stop the dnsmasq service as a result of the dhcp-client after a link becomes available, but could not find such an option.