ubuntu, updated
Where are the DNS settings?
systemd-resolved, the 127.0.0.53 stub, where to set DNS servers, and how to test and flush DNS.
Why /etc/resolv.conf says 127.0.0.53
Ubuntu uses systemd-resolved as a local DNS cache. Every program asks the stub at 127.0.0.53, and systemd-resolved forwards the question to the real DNS servers.
flowchart LR
A["App"] --> R["/etc/resolv.conf
nameserver 127.0.0.53"]
R --> S["systemd-resolved
(cache)"]
S --> D["Real DNS servers
from Netplan / DHCP"]
/etc/resolv.conf is a symlink generated by systemd-resolved. Don’t edit it, your changes will be overwritten.
Where to set DNS servers
| Where | When |
|---|---|
Netplan, per interface: nameservers: | The normal way. See the example below. |
| DHCP | Default, if the interface uses dhcp4: true |
/etc/systemd/resolved.conf.d/*.conf | Global DNS for all interfaces, or fallback |
/etc/hosts | Single static names, checked before DNS |
Netplan (in the interface block, then sudo netplan apply):
nameservers:
addresses: [192.168.10.1, 9.9.9.9]
search: [corp.example.com]
To ignore DNS servers from DHCP and use only yours, add under the interface:
dhcp4-overrides:
use-dns: false
Global, for every interface:
[Resolve]
DNS=192.168.10.1 9.9.9.9
Domains=corp.example.com
Then sudo systemctl restart systemd-resolved.
Cheat sheet
| What | Command |
|---|---|
| Which DNS servers are used, per interface | resolvectl status |
| Resolve a name (through the cache) | resolvectl query example.com |
| Ask a specific DNS server | dig @9.9.9.9 example.com |
| Short answer only | dig +short example.com |
| Reverse lookup | dig -x 192.168.10.20 |
| Flush the DNS cache | sudo resolvectl flush-caches |
| Cache statistics | resolvectl statistics |
| Resolve like an app does (incl. /etc/hosts) | getent hosts example.com |
dig and nslookup come from bind9-dnsutils (installed on Ubuntu Server).
/etc/hosts
For a few fixed names without a DNS server:
127.0.0.1 localhost
127.0.1.1 srv-web01
192.168.10.30 db01.corp.example.com db01
Applies immediately, no restart needed.
Troubleshooting
digworks but apps don’t:digasks DNS directly and skips/etc/hostsand the search domain. Test withgetent hosts NAME.- Short names like
db01don’t resolve: add asearch:domain. - Changes have no effect: check that your interface actually got them with
resolvectl status.