Quick Summary: The error
listen tcp 0.0.0.0:53: bind: address already in use(ordnsmasq: failed to create listening socket for port 53: Address already in use) occurs on Ubuntu, Debian, and modern Linux distributions when attempting to run a local DNS server (such as Pi-hole, AdGuard Home, CoreDNS, BIND9, or dnsmasq) whilesystemd-resolvedis actively binding to port 53 via its built-inDNSStubListener.
Understanding the Root Causes
Modern Linux distributions (including Ubuntu 18.04+ and Fedora) ship with systemd-resolved enabled by default to manage local DNS caching and per-interface name resolution. By default, it opens a local stub resolver listening on 127.0.0.53:53 (TCP and UDP). Conflicts arise when:
- Wildcard Port 53 Binding: DNS applications like Dockerized Pi-hole, AdGuard Home, or CoreDNS attempt to bind to
0.0.0.0:53(all interfaces), which collides directly with127.0.0.53:53. - Symlinked /etc/resolv.conf: Because
/etc/resolv.confis managed as a symlink pointing to/run/systemd/resolve/stub-resolv.conf, simply stoppingsystemd-resolvedwithout updating/etc/resolv.confbreaks all outbound DNS lookups on the host machine. - Secondary Local Resolvers: Running Libvirt/QEMU’s internal
dnsmasqor NetworkManager DNS plugins alongside a custom DNS service.
Step 1: Quick Triage – Confirm systemd-resolved is Holding Port 53
Verify which process is currently listening on TCP and UDP port 53 before modifying network settings:
# Inspect active listeners on port 53
sudo ss -tulpn | grep :53
# Expected output confirming systemd-resolved conflict:
# udp UNCONN 0 0 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=842,fd=13))
# tcp LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=842,fd=14))
Step 2: Disable DNSStubListener Cleanly (Recommended)
Rather than disabling systemd-resolved entirely, the cleanest approach is disabling only its port 53 stub listener while keeping systemd’s upstream DNS management intact:
# 1. Create a drop-in configuration directory for resolved
sudo mkdir -p /etc/systemd/resolved.conf.d
# 2. Disable DNSStubListener and configure an explicit fallback DNS
sudo tee /etc/systemd/resolved.conf.d/no-stub.conf <<EOF
[Resolve]
DNS=1.1.1.1 8.8.8.8
DNSStubListener=no
EOF
# 3. Replace the stub resolv.conf symlink with the non-stub upstream file
sudo rm -f /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
# 4. Restart systemd-resolved to release port 53
sudo systemctl restart systemd-resolved
Step 3: Alternative – Bind Your DNS Service to a Specific Interface IP
If you prefer to leave systemd-resolved untouched on 127.0.0.53:53, configure your Docker container or DNS daemon to bind strictly to your host’s LAN IP address instead of 0.0.0.0:
# Find your host's primary LAN IP address (e.g., 192.168.1.50)
ip -4 addr show scope global | grep inet
# In docker-compose.yml, bind port 53 strictly to the LAN IP:
services:
pihole:
image: pihole/pihole:latest
ports:
- "192.168.1.50:53:53/tcp"
- "192.168.1.50:53:53/udp"
- "80:80/tcp"
Verification & Testing Steps
Confirm that port 53 is free on 127.0.0.53 and that the host OS can still resolve external domain names cleanly:
# 1. Verify port 53 is no longer held by systemd-resolved
sudo ss -tulpn | grep :53
# Expected output: (empty, or only your newly started DNS service)
# 2. Verify host DNS resolution still works
dig +short example.com
# Or using getent:
getent hosts example.com
# 3. Start your DNS container or service and confirm port 53 binding succeeds
docker compose up -d
Troubleshooting Summary Comparison
| Scenario | Primary Root Cause | Recommended Solution |
|---|---|---|
| Docker DNS (Pi-hole / CoreDNS) fails to bind | systemd-resolved holds 127.0.0.53:53 |
Set DNSStubListener=no and symlink /run/systemd/resolve/resolv.conf |
| Host loses internet DNS after stopping resolved | /etc/resolv.conf points to dead stub file |
Relink /etc/resolv.conf to /run/systemd/resolve/resolv.conf |
| Cannot modify host systemd settings | Shared host requires default stub resolver | Bind container ports to specific LAN IP (e.g., 192.168.1.50:53:53) |
Port 53 held by dnsmasq instead |
Libvirt or NetworkManager spawned local dnsmasq | Disable NetworkManager dns=dnsmasq or stop conflicting service |
Leave a Reply