Let's talk about DNS client configuration. So, DNS is for name resolution. And DNS is
the internet-based system that ensures that all hosts have a unique name and can be reached
by it. To get the IP address that belongs to the name, the internet DNS server is contacted.
Traditionally, the file etcresolve.conf on Linux has always taken care of the DNS
name resolution. We call it the DNS resolver. The file etchost can be used to resolve host
names on the local network without using DNS. So, if you want to use a local host by name,
put its name and IP address in etchosts. And if the host name is defined in etchost,
it will have higher priority than DNS host names, which is, by the way, managed in the
file etcnsswhich.conf. Now, in most cases, you want to set up a DNS client. As mentioned,
resolve.conf is the old standard. On network manager systems, the file can be written directly
or is managed by network manager. On systemd networkd systems, like Ubuntu, a different
approach is used. And that is where systemd resolved comes in. So, systemd resolved is a
systemd component that manages DNS name resolution. And it runs as a systemd service that
communicates with the networking stack and makes sure that multiple DNS sources can be used
and DNS records are cached. You can check the current status using systemctl status systemd
resolved. And use resolvectl status for information about the current DNS configuration.
If ever you want to overwrite DNS configuration, you edit the file uselib systemd resolve.conf
or better etcsystemd resolve.conf. And then you restart systemd resolved to pick up your edits
and write the correct information to your etcresolve.conf.
So, first, systemctl status on systemd resolved
d is showing that systemd resolved is actively running. And that means that this is managing
your DNS configuration. So, let's do something funny. And let me use sudo vim on etcresolve.conf.
And there I'm going to change my configuration. Let me put a
comment sign in front of it. And I make it nameserver 8888. All right. Next, I'm going to
use a sudo systemctl restart systemd resolved. And back to my resolve.conf. And as you can see,
the nameserver 8888 has disappeared. And that is because if you want to overwrite your DNS configuration,
well, actually, it's saying it right here. And this is the file. So, in fact, if I want to change
my configuration, well, I need to be in uselib systemd resolve.conf. That is the input file
that is actually being used. And, hey, do you remember what is going on with these files in uselib?
Uselib is supposed to be provided by packages. Do not edit it. Instead of editing this file,
copy the file to etcsystemd resolve.conf and edit that. And that will make sure that your edits
find their way into the resolve.conf configuration. Confusing, huh? But you better be aware of it.
Otherwise, it won't ever work.