dnsmasq : failed to create listening socket for port 53: Address already in use
By default Dnsmasq tries to bind the port over all interfaces. Where --bind-interfaces
only interface declared in the configuration.
man dnsmasq
-z, --bind-interfaces
On systems which support it, dnsmasq binds the wildcard address,
even when it is listening on only some interfaces. It then
discards requests that it shouldn't reply to. This has the
advantage of working even when interfaces come and go and change
address. This option forces dnsmasq to really bind only the
interfaces it is listening on. About the only time when this is
useful is when running another nameserver (or another instance
of dnsmasq) on the same machine. Setting this option also
enables multiple instances of dnsmasq which provide DHCP service
to run in the same machine.
--bind-dynamic
Enable a network mode which is a hybrid between
--bind-interfaces and the default. Dnsmasq binds the address of
individual interfaces, allowing multiple dnsmasq instances, but
if new interfaces or addresses appear, it automatically listens
on those (subject to any access-control configuration). This
makes dynamically created interfaces work in the same way as the
default. Implementing this option requires non-standard
networking APIs and it is only available under Linux. On other
platforms it falls-back to --bind-interfaces mode.
Similar cases:
- dnsmasq, serve different ip addresses based on interface used
- How to avoid conflicts between dnsmasq and systemd-resolved?
More advance related topic:
Related videos on Youtube
Ravexina
I have studied software engineering and artificial intelligence. I Love *nix operating systems, programming, learning and of course... Music :) I'm a MOD at AU, and if you have any question or concern about my decisions/actions, please post them at: https://meta.askubuntu.com and not to my emāil. If you like to contact me, my Ǧmāil is same as my Ūsĕrņame ;) Please don't Ask your questions using ĕmāil... thanks :-)
Updated on September 18, 2022Comments
-
Ravexina over 1 year
I'm trying to configure
dnsmasq
to work along withNetworkManager
, the problem is when I try to run the service it fails with:dnsmasq: failed to create listening socket for port 53: Address already in use
However nothing is listening on
127.0.0.1:53
:sudo ss -alpn sport = 53 src 127.0.0.1
The above command has no output!
Here is what my
/etc/dnsmasq.conf
looks like:$ grep '^[^#]' /etc/dnsmasq.conf
no-resolv server=8.8.8.8#53 listen-address=127.0.0.1 cache-size=50
The issue can be fixed if I enable
bind-interfaces
in/etc/dnsmasq.conf
.Why should I enable this? the comments states that:
About the only time you may need this is when running another nameserver on the same machine.
So I thought the issue might come from
systemd-resolved.service
and sure it was. after stopping it:sudo systemctl stop systemd-resolved.service
now
dnsmasq
is working fine withoutbind-interfaces
option being enabled.
I'm running Ubuntu 18.04.1.
Installed usingdebootstrap
and my default renderer isNetworkManager
which is working fine.
My questions are:
- Why do I have to enable
bind-interfaces
? - Is it okay to just disable
systemd-resolved
service? if it is how should I getdnsmasq
to control/etc/resolv.conf
? - And more important, why I'm getting that weird error message when nothing is listening on port
53
?
-
steeldriver over 5 yearsAt least on my box, systemd-resolved listens on 127.0.0.53:53 rather than 127.0.0.1:53 so try
sudo ss -alpn sport = 53 src 127.0.0.53
- or go oldschool and use something likesudo netstat -nlpt | grep :53
-
goo over 5 yearsOr
sudo lsof -i tcp:53
-
Ravexina over 5 yearsI knew that
systemd-resolved
is listening on127.0.0.53:53
. The thing I wasn't aware of was when something is listening onlo
it has effects on all IP addresses oflo
. After playing around withnetcat
I figure it out... poor networking knowledge.
- Why do I have to enable