Before connecting, a program asks the system for the name's address. Where the system looks is written in two files.
A program does not look the address up itself: it calls the resolver, the part of the system that finds an address for a name. getent hosts name prints the resolver's answer: the address and the name if it found one, nothing if it did not. curl gets the same answer from the resolver.
The hosts: line in /etc/nsswitch.conf says where to look. It usually reads files dns: first the /etc/hosts file, then DNS.
| Source | What it holds |
|---|---|
/etc/hosts |
"address name" lines on the machine itself |
| DNS server | an answer to "which address does this name have", over the network |
The resolver takes the DNS server's address from the nameserver line in /etc/resolv.conf.
Ask the system
Ask the system resolver about the name web.lab.test, then look at where it searches for the address and which DNS server is in the settings.
First, predict
What will getent hosts web.lab.test print?
Now start the exercise, run the command and compare your prediction with the output.