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

WhereWhen
Netplan, per interface: nameservers:The normal way. See the example below.
DHCPDefault, if the interface uses dhcp4: true
/etc/systemd/resolved.conf.d/*.confGlobal DNS for all interfaces, or fallback
/etc/hostsSingle 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

WhatCommand
Which DNS servers are used, per interfaceresolvectl status
Resolve a name (through the cache)resolvectl query example.com
Ask a specific DNS serverdig @9.9.9.9 example.com
Short answer onlydig +short example.com
Reverse lookupdig -x 192.168.10.20
Flush the DNS cachesudo resolvectl flush-caches
Cache statisticsresolvectl 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

§ home
~/knubertus/home/
1,1 Top