4

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.

1
  • I have exactly the same case. Did you find a working solution?
    – nazikus
    Commented Jun 24, 2020 at 10:50

1 Answer 1

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.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .