1

I'm trying to set up dnsmasq on AWS Ubuntu 20.4 by following this link.

However, I can't seem to get around the error dnsmasq: failed to create listening socket for port 53: Address already in use

I've tried the steps in these posts with no success:

  1. https://askubuntu.com/questions/191226/dnsmasq-failed-to-create-listening-socket-for-port-53-address-already-in-use

  2. https://discourse.pi-hole.net/t/dnsmasq-failed-to-create-listening-socket-for-port-53-permission-denied/16436

  3. https://jonamiki.com/2020/01/29/dnsmasq-failed-to-create-listening-socket-for-port-53-address-already-in-use/

  4. https://askubuntu.com/questions/1062651/dnsmasq-failed-to-create-listening-socket-for-port-53-address-already-in-use

The only thing that has had any obvious impact has been sudo systemctl stop systemd-resolved.service which changed the error message from dnsmasq: failed to create listening socket for port 53: Address already in use to dnsmasq: failed to create listening socket for 127.0.0.1: Address already in use

I'm not sure what's actually running on 53 because, if I run sudo ss -alpn sport = 53 src 127.0.0.1 there is no output, nothing is apparently listening on port 53. However, If I run sudo ss -lp "sport = :domain" my output is:

Netid       State        Recv-Q       Send-Q             Local Address:Port               Peer Address:Port      Process                                  
udp         UNCONN       0            0                        0.0.0.0:domain                  0.0.0.0:*          users:(("dnsmasq",pid=2059,fd=4))       
udp         UNCONN       0            0                           [::]:domain                     [::]:*          users:(("dnsmasq",pid=2059,fd=6))       
tcp         LISTEN       0            32                       0.0.0.0:domain                  0.0.0.0:*          users:(("dnsmasq",pid=2059,fd=5))       
tcp         LISTEN       0            32                          [::]:domain                     [::]:*          users:(("dnsmasq",pid=2059,fd=7))    

My /etc/dnsmasq.conf looks like:

no-resolv
server=8.8.8.8#53
listen-address=127.0.0.1
cache-size=50

I tried enabling bind-interfaces in /etc/dnsmasq.conf which made no difference.

And I also tried to make sure to stop systemd-resolved service and I masked it so auto start on reboot.

sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved
sudo systemctl mask systemd-resolved

Again, no difference.

Checking sudo systemctl dnsmasq.service returns:

Unknown operation dnsmasq.service.
ubuntu@ip-172-31-27-116:~$ sudo systemctl status dnsmasq.service
● dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server
     Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2022-02-13 19:55:05 UTC; 36s ago
    Process: 3381 ExecStartPre=/usr/sbin/dnsmasq --test (code=exited, status=0/SUCCESS)
    Process: 3382 ExecStart=/etc/init.d/dnsmasq systemd-exec (code=exited, status=2)

Feb 13 19:55:04 ip-172-31-27-116 systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
Feb 13 19:55:05 ip-172-31-27-116 dnsmasq[3381]: dnsmasq: syntax check OK.
Feb 13 19:55:05 ip-172-31-27-116 dnsmasq[3382]: dnsmasq: failed to create listening socket for 127.0.0.1: Address already in use
Feb 13 19:55:05 ip-172-31-27-116 dnsmasq[3382]: failed to create listening socket for 127.0.0.1: Address already in use
Feb 13 19:55:05 ip-172-31-27-116 dnsmasq[3382]: FAILED to start up
Feb 13 19:55:05 ip-172-31-27-116 systemd[1]: dnsmasq.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
Feb 13 19:55:05 ip-172-31-27-116 systemd[1]: dnsmasq.service: Failed with result 'exit-code'.
Feb 13 19:55:05 ip-172-31-27-116 systemd[1]: Failed to start dnsmasq - A lightweight DHCP and caching DNS server.

2 Answers 2

1

You are already running dnsmasq on 127.0.0.1.

0.0.0.0 is shorthand for all interfaces which includes 127.0.0.1.

Either run systemctl stop dnsmasq and check whether it has stopped, or issue kill -9 2059 and try again.

2
  • After running sudo systemctl stop dnsmasq sudo systemctl dnsmasq.service returns Unknown operation dnsmasq.service. is this expected? running dig ubuntu.com x 2 shows it is dropping from 11ms to 0ms on the second command so something is still caching despite sudo stop
    – L23P
    Feb 14, 2022 at 10:57
  • The error message indicates your sudo systemctl… command missed the word stop so it did not do anything at all.
    – telcoM
    Oct 22, 2022 at 8:27
0

It's in use by systemd-resolved, check listening ports and you will see.

  • As of systemd 232 (released in 2017) you can edit /etc/systemd/resolved.conf (not /etc/resolv.conf) and add this line:
    DNSStubListener=no
    
    Make sure that the file has the [Resolve] section header on top.
  • then
    sudo systemctl restart systemd-resolved
    
  • then restart dnsmasq and check its status and logs.

You must log in to answer this question.

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