Failed to run: dnsmasq - Address already in use

lxc network set lxdbr0 ipv4.routes $routes

gives:
error: Failed to run: dnsmasq --strict-order --bind-interfaces --pid-file=/var/lib/lxd/networks/lxdbr0/dnsmasq.pid --except-interface=lo --interface=lxdbr0 --quiet-dhcp --quiet-dhcp6 --quiet-ra --listen-address=10.21.98.1 --dhcp-no-override --dhcp-authoritative --dhcp-leasefile=/var/lib/lxd/networks/lxdbr0/dnsmasq.leases --dhcp-hostsfile=/var/lib/lxd/networks/lxdbr0/dnsmasq.hosts --dhcp-range 10.21.98.2,10.21.98.254,1h --listen-address=fd42:7bb5:714c:966::1 --enable-ra --dhcp-range ::,constructor:lxdbr0,ra-stateless,ra-names -s lxd -S /lxd/ --conf-file=/var/lib/lxd/networks/lxdbr0/dnsmasq.raw -u nobody: dnsmasq: failed to create listening socket for 10.21.98.1: Address already in use

When I see this fail, I just retry and it works with no error.
Anyone saw this before?
Any idea ?

That means that you have an existing DNS or DHCP server running on your machine which is binding all interfaces, preventing LXD from listening on lxdbr0.

sudo netstat -lnp | grep ":53 " should show you what it is (it’s often bind9/named).
Once you figure out what it is, you have two options:

  • Remove that conflicting DNS server (if you don’t actually need it)
  • Configure it to only bind to the interfaces you actually need it on

netstat -lnp | grep ":53 "

tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 2005/dnsmasq
tcp6 0 0 :::53 :::* LISTEN 2005/dnsmasq
udp 0 0 0.0.0.0:53 0.0.0.0:* 2005/dnsmasq
udp6 0 0 :::53 :::* 2005/dnsmasq

Hmm.
I’m not sure what to do here.

This says that there is a dnsmasq process that is binding to all network interfaces (0.0.0.0:*).
By doing so, the dnsmasq from LXD cannot start.

Give this a try,

  1. sudo systemctl stop dnsmasq so that the distro dnsmasq stops working.
  2. sudo systemctl restart lxd so that LXD restarts and LXD’s dnsmasq gets the chance to bind on the lxdbr0 network interface first.
  3. sudo systemctl start dnsmasq to start again the distro dnsmasq.

In most cases, you don’t actually want a system-wide dnsmasq daemon.
The distro-managed dnsmasq daemons tend to be only bound to your loopback device.

Unless you remember installing/configuring that system-wide dnsmasq, I’d recommend just removing it with apt remove dnsmasq. Note that the dnsmasq package is different from the dnsmasq-base package, the former is the system-wide daemon, the latter is the per-interface dnsmasq which a bunch of packages (including LXD) use.

Ok.

Removed dnsmasq , installed bind, installed dnsmasq-base and all seems fine now.

Thank you !

Hello,

For the record, I got exactly the same behaviour after doing an installation of LXC (2.0.7) and LXD (3.9) under Debian Stretch 9.7.

For me, the running dnsmasq daemon was run by the installation of lxc.

My workaround was just to stop dnsmasq with systemctl stop dnsmasq as @simos said and re-run lxd init.

Yeah, I had the same problem with Bind… Stopping the service and re-running lxd init did the trick

What if I DO want a system-wide dnsmasq daemon? How do I configure them to avoid conflicts?