Ubuntu 內建的 systemd-resolved 會在本機 127.0.0.53:53 啟動 DNS stub listener,導致要自行架設 DNS 服務(如 dnsmasq、Pi-hole)時 53 埠被佔用而無法啟動。本文記錄關閉 stub listener、釋放 53 埠的步驟。
systemd-resolved
127.0.0.53:53
編輯 systemd-resolved 設定檔。
sudo nano /etc/systemd/resolved.conf
將 DNSStubListener 取消註解並設為 no。
DNSStubListener
no
[Resolve] #DNS= #FallbackDNS= #Domains= #LLMNR=no #MulticastDNS=no #DNSSEC=no #DNSOverTLS=no #Cache=yes DNSStubListener=no #ReadEtcHosts=yes
將 /etc/resolv.conf 指向 systemd-resolved 實際產生的設定檔。
/etc/resolv.conf
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
讓設定生效,53 埠即釋出。
sudo systemctl restart systemd-resolved
Deleting the wiki page "53 埠被占用" cannot be undone. Continue?