0

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.

0

The way I would approach this is to write a bash script that starts dnsmasq based on the output of dhclient. If dhclient doesn't get a response, start dnsmasq. Should actually be quite simple. Without looking, I assume dhclient will give a non-zero exit code if it fails to obtain a DHCP lease.

Trigger a script with udev, or by putting it in /etc/network/interfaces for example and if dhclient gives a non-zero exit code, start dnsmasq.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.