- In this video we'll talk about host names.
So how do you manage them?
Well, first let's talk about resolving host names.
DNS is commonly used for host name resolving.
It's a worldwide standard and it's
like you use all the times.
But there is also etc host.
Etc host is used to maintain local list
of host names and matching IP addresses.
Now the interesting question is,
how does etc host relate to DNS?
Well, the order for host name resolution is
in /etc/nsswitch.conf.
So you, need to check out /etc/nsswitch.
It's a name service switch
and it is used to define the order
in which host name resolution should happen.
And the line that you see here might be what you find
in it. Depends on your distribution.
Now the important part is that hosts defines the order
and as long as files comes before DNS,
then etc host is always going to win,
and can be used to override if you want to.
/Etc/resolv.conf is the old standard
for configuring DNS name servers.
And on network manager systems the file can be
written directly, or it is managed by network manager.
And on systemd-networkd systems,
a different approach is used.
Here the file is managed with systemd-resolved.
And etc resolved is a symbolic link to
/run/systemd/resolve/stub-resolv.conf
for automatically managing it.
Let's check out how the simulation works
between etc hosts and DNS.
So here we are on the center s machine and let me
use ping.google.com. And there we go,
We are getting an answer from
142.250.69.238.
Now if I would use etc hosts. And in etc host,
I am setting 192.168.29.2
and I call it google.com.
And then we repeat ping.google.com.
There we can see that google.com is now 192.168.29.2.
Which is obviously not the real Google, but this is just
showing that etc host is always winning
from the DNS configuration.
And that is because of /etc/nsswitch.conf
in which we can find this host's line. Let's look it up.
And in this host's line we have files DNS myhostname.
I'm going to comment it out.
I like commenting it out if I'm playing with configuration
files so that it's easy to get back to the previous
configuration. And now I'm setting to DNS files.
(keyboard clicking)
And what is going to happen now,
if we ping google.com, there you go.
The internet is winning.
So everything because of /etc/nsswitch.conf.
Before continuing, I do advise you to revert
to the original situation.
(keyboard clicking)
There we go. Now it should be working.
Just to avoid some nasty surprises later on.