Search code examples
network-programmingnamespacesdnsmasq

Unable to run multiple dnsmasq dhcp servers on ubuntu 18.04


I've created a new network namespace for USB-ethernet and Wireless interface.

I run a DNSMASQ dhcp server on an interface with
sudo dnsmasq --port 5353 --interface wlp2s0 -F 123.12.1.101,123.12.1.200,24h
Which works like a charm.

I then want to set up another DNSMASQ dhcp server on the other interface with:
sudo dnsmasq --port 5454 --interface enx65ad574sa -F 123.12.1.101,123.12.1.200,24h
But this just reports dnsmasq: failed to bind DHCP server socket: Address already in use.

I am able to setup multiple dnsmasq dhcp servers if i run the dnsmasq outside the namespace, but inside a namespace, i can only have it running once.

If i create a configuration file:

interface=wlp2s0
dhcp-range=wlp2s0,123.12.1.101,123.12.1.200,255.255.255.0,24h
interface=enx65ad574saaw
dhcp-range=enx65ad574saaw,192.168.0.101,192.168.0.200,255.255.255.0,24h
listen-address=::1,127.0.0.1,192.168.0.1,123.12.1.1

It also works just fine on both interfaces inside the namespace... So what's the difference? I need to run this dynamically from the commandline, so i can't use the configuration file.


Solution

  • I ended up creating 2 separate dnsmasq configuration files, both has dhcp serve setup on the same interface, and then run the configarions concurrently in each their own network namespace - That means when the wireless interface is added to the network namespace, dnsmasq is already serving as dhcp server on the interface.

    Apparently, setting up and starting 2 dnsmasq, that has their own configuration but with the same interface in both, does not interfere or break each other, and works quite seamlessly (atleast when they are started in separate network namespaces).