Menu
Coddy logo textTech

Recap: Names

Lesson 9 of 47 in Coddy's Networking with the Terminal course.

A name has to become an address before anything connects, and two things can answer the question.

Your machine checks /etc/hosts first. Whatever it finds there wins outright, and DNS is never asked. Only if the name is absent does it go out to a DNS resolver, which usually replies from a cache, hence the familiar non-authoritative label.

cat /etc/hosts        # checked first, and it wins
nslookup example.com  # ask DNS when the file has nothing

Records come in types, A and AAAA for addresses, CNAME for an alias, MX for mail, TXT for free text, and each carries a TTL that decides how long it may be cached.

The habit worth keeping: resolving and connecting are two separate steps, and knowing which one failed is most of the diagnosis.

challenge icon

Challenge

Medium

Read the answer the hosts file gives, in the other direction.

In the last challenge you printed the address for the name. Now print the name that 127.0.0.1 maps to, taking it from the first line of /etc/hosts that starts with that address. The expected output is exactly:

localhost

^ in a grep pattern means "at the start of the line", which keeps you from matching an address that merely contains those digits.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Networking with the Terminal

Practice on your own: Terminal playground