With many linux systems moving from
/etc/resolv.conf to systemd I was unsure how to set my DNS servers.
Add the following to
Then restart with:
sudo systemctl restart systemd-resolved
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
Following the comments in
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:
A space-separated list of IPv4 and IPv6 addresses to use as system DNS servers.
A space-separated list of IPv4 and IPv6
addresses to use as the fallback DNS servers
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.
dig to check DNS records, such as with
dig http://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.