Dnsmasq fails on initial startup, succeeds on restart (unknown interface, or failed to create listening socket)

Taking a new F34 server installation and configuring it to be a DHCP and DNS server using dnsmasq, I consistently see a failure at boot where it appears the interface is not yet up. (Unmodified dnsmasq.service, shown below). If I manually start the service again a few seconds later, it succeeds. Seems like a systemd configuration issue, but the service file looks like it has the right dependency order. What am I not getting?

[Unit]
Description=DNS caching server.
After=**network.target**

[Service]
ExecStart=/usr/sbin/dnsmasq -k

[Install]
WantedBy=multi-user.target

Error:

Sep 28 16:01:40 workhorse dnsmasq[882]: dnsmasq: failed to create listening socket for 192.168.1.18: Cannot assign requested address
Sep 28 16:01:40 workhorse dnsmasq[882]: failed to create listening socket for 192.168.1.18: Cannot assign requested address
Sep 28 16:01:40 workhorse dnsmasq[882]: FAILED to start up

dnsmasq.conf contains the below (interface has static IP address 192.168.1.18)
listen-address=127.0.0.1,192.168.1.18

Thanks for any pointers.I’ve been scratching my head for a couple of Fedora releases and server builds, and am tired of settling for logging in and manually starting the service.

1 Like

Unfortunately, no joy for me.

7:25 PM FAILED to start up  dnsmasq
7:25 PM unknown interface eno1 dnsmasq
mhdave@workhorse ~]$ cat /etc/dnsmasq.d/setif.conf
interface=eno1

Then, after restarting dnsmasq:
Sep 28 19:32:01 workhorse dnsmasq-dhcp[1537]: DHCP, sockets bound exclusively to interface eno1

So, seems definitely related to a boot startup timing issue.
Thanks for verifying it works well for you; I just need more of your magic.

https://src.fedoraproject.org/rpms/dnsmasq/blob/rawhide/f/dnsmasq.service#_6-7

Note that to use bind-dynamic, you need to comment out bind-interfaces.

Perfect, thanks. Two different approaches are given in that link:

; Use bind-dynamic or uncomment following to listen on non-local IP address
;After=network-online.target

I added the After network-online target and had the success I’ve been seeking for so long However the other approach is the bind-dynamic dnsmasq.conf configuration option, which is likely what I needed and will also try. Thanks, @vgaetera

1 Like