Loading
0xA0Lesson 11 of 15

Resolve names with DNS

Follow the lookup from a name to a network address.

25 min 7-question quiz
By the end of this lesson you can
  • Describe how a resolver walks the DNS hierarchy.
  • Predict how caching and TTLs change the work a lookup takes.
  • Choose the right DNS record type for a job.

You remember names, but packets need addresses. The Domain Name System connects the two, and it does so without a central database. It's a worldwide system that answers trillions of questions a day because no single server has to know everything.

A tree of delegation

Names are read from right to left. Each level delegates to the one below it, so the root servers don't know where www.learn.example is. They only know who runs example., and that server only knows who runs learn.example.

.com.org.example.github.com.wikipedia.org.learn.example.www.learn.example.Root serversTop-level domainsAuthoritative zoneThe recordA 203.0.113.8
DNS is a tree read from right to left. Each level knows only who to ask next, and only the last one holds the answer.

The resolver does the walking

Your device doesn't do this itself. It asks a recursive resolver, usually run by your provider or a public service such as 1.1.1.1. The resolver asks the root, follows the referrals down to the authoritative server that holds the answer, and returns it to you.

The resolver then caches everything it learned. Each record carries a TTL, the number of seconds it may be reused. Referrals are cached as well, which is why looking up a second name in the same domain is cheap.

Try it

Up to 15 XP

Run a caching resolver

Try this sequence and predict the query count each time:

  1. Look up www.learn.example on a cold cache.
  2. Look it up again.
  3. Look up docs.learn.example. The answer isn't cached, but something useful is.
  4. Wait 1 hour, then repeat the first lookup. Which entries survived?

The clock only moves when you wait, so you can compare TTLs in the cache table.

Time since the resolver started: 0 secondsPredicted 0/0
Look up a name
Let time pass
Resolver cache

Empty. Every lookup starts at the root.

Queries sent so far
0

More than addresses

DNS stores several kinds of record. These are the ones you'll see most:

Try it

Up to 15 XP

Match the job to the record type

You're setting up a domain. Pick the record type for each job.

0 of 5 sortedScore 0/0
  • “Point learn.example at 203.0.113.8”

  • “Point learn.example at 2001:db8::8”

  • “Make www.learn.example an alias of learn.example”

  • “Say which server receives email for learn.example”

  • “Prove you own the domain to a cloud provider”

To see real answers, use dig on macOS and Linux, or nslookup on Windows. The number after the name is the remaining TTL in seconds:

terminal
$ dig +noall +answer www.learn.example
www.learn.example.   300   IN   A   203.0.113.8

You can watch a cache at work. Ask a resolver the same question twice, 40 seconds apart, and the TTL counts down, because the second answer came from memory.

terminal
1$ dig +noall +answer www.learn.example
2www.learn.example.   300   IN   A   203.0.113.8
3
4$ dig +noall +answer www.learn.example
5www.learn.example.   260   IN   A   203.0.113.8

Try it

Up to 15 XP

Read dig output

dig is the tool for asking DNS questions directly. Click the line that answers each question.

Round 1 of 4: Find the answerScore 0/0

Which line holds the address you asked for?

$ dig learn.example

Key takeaways

  • DNS is a delegated tree, and each level only knows who to ask next.

  • A recursive resolver walks the tree and caches what it learns.

  • A TTL limits how long an answer can be reused, so it's a trade-off between speed and freshness.

Lesson quiz

7 questions · pass with 5 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…