Linux Labs

Networking / Stage 9 of 14

Why the address works and the name does not

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 8 · on a machine · 5 min

Who looks up the address for a name

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.

Exercise · look

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.

Sign in and start The machine is available after signing in
Ubuntu 24.04
Loading…