brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: DNSStubListener=no frees port 53 from systemd-resolved for Pi-hole

Systemd
~/tips/tip-systemd-stub-listener

DNSStubListener=no

Turn off the local stub resolver so Pi-hole or another DNS server can bind to port 53.

Installing Pi-hole or AdGuard Home on Ubuntu often fails with an error that port 53 is already in use. The culprit is the stub resolver of systemd-resolved on 127.0.0.53.

Switch the stub off in a drop-in:

sudo mkdir -p /etc/systemd/resolved.conf.d
sudo tee /etc/systemd/resolved.conf.d/no-stub.conf <<'EOF'
[Resolve]
DNSStubListener=no
EOF
sudo systemctl restart systemd-resolved

The resolved.conf man page says the default is yes, listening on 127.0.0.53 and 127.0.0.54, port 53, over UDP and TCP; no disables it. After the restart, sudo ss -lunp 'sport = :53' should show nothing until Pi-hole starts.

There is a catch in /etc/resolv.conf. On Ubuntu it is usually a link to stub-resolv.conf, which points at the stub you just turned off, so the box itself can no longer resolve names. Point it at the file with the real upstream servers instead:

sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

I would do that before anything else, or package installs on the box may start failing. Once Pi-hole runs, you can also put DNS=127.0.0.1 in resolved’s config so the server uses its own Pi-hole.

Further reading: resolved.conf man page, systemd-resolved.service man page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link