With many linux systems moving from /etc/resolv.conf to systemd I was unsure how to set my DNS servers.
Summary
Add the following to /etc/systemd/resolved.conf:
DNS=1.1.1.1
FallbackDNS=8.8.8.8
Then restart with:
sudo systemctl restart systemd-resolved
Check status
You can use systemd-resolve --status or sudo resolvectl status to see the current status and should see “DNS Servers” listed. Using systemd-resolve --status | grep 'Server' shows all DNS servers both global and local to a specific network, partly because more information is shown when piped, such as with systemd-resolve --status | cat. These might be
Man pages
Following the comments in resolv.conf suggests man systemd-resolved where the inner workings are described in more detail, but man resolved.conf is was more helpful in working out what to set:
DNS=
A space-separated list of IPv4 and IPv6 addresses to use as system DNS servers.
FallbackDNS=
A space-separated list of IPv4 and IPv6
addresses to use as the fallback DNS servers
Domains=
A space-separated list of domains. These domains are used as search suffixes when resolving single-label host names (domain names which contain no dot), in order to qualify them into fully-qualified domain names (FQDNs).
I’m curious what Domains= does, so might investigate that later. Edit: These are search domains and are prepended if you lookup a domain/url without a dot in it. E.g. if I added Domains=jameslearnt.com, then I’d be able to enter today in my URL bar and have that take me to today.jameslearnt.com as a kind of online hosts file shortcut.
Troubleshooting
Using dig to check DNS records, such as with dig www.jameslearned.com -t cname, can be traced by appending +trace to the command.
Caches can be flushed with sudo systemd-resolve --flush-caches or sudo service dns-clean start.
For more detailed diagnostics it is possible to set sytemd-resolved into debug mode and trace the lookups, but I didn’t end up needing to do this.