Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
How the Web Works  ›  Lesson

Domain Names and DNS

DNS and how it works? 14 minA domain name is a human-friendly label read from right to left, and DNS resolves it to an IP address by asking root, top-level-domain and authoritative servers, caching each answer for its TTL.

Domain Names and DNS

Nobody wants to type 203.0.113.10 to buy a book. People remember bookshop.example, but packets only understand IP addresses. The Domain Name System (DNS) is the internet's phone book, and when a deploy "works for me but not for them", DNS is often the reason.

The rule

Names are for people; DNS turns them into addresses.

A domain name is read from right to left, from the most general part to the most specific:

  • example in api.bookshop.example is the top-level domain (TLD), like .com, .org or .in. (.example itself is reserved for examples like ours.)
  • bookshop.example is the domain you rent every year from a registrar.
  • api.bookshop.example is a subdomain. Once you own the domain, you can create as many as you like.

A domain's authoritative name server holds its records. The common ones:

Record Points a name at
A an IPv4 address
AAAA an IPv6 address
CNAME another name (an alias)
MX the mail servers for the domain
TXT free text, often used to prove you own the domain

Every record has a TTL (time to live) in seconds: how long others may cache the answer before asking again.

dig api.bookshop.example A

A typical answer line reads api.bookshop.example. 300 IN A 203.0.113.10: the name, a TTL of 300 seconds, and the address.

The shortcut

Read the name right to left, and you have the order of the lookup. Each dot is one step down a tree, and a resolver walks down it the same way.

Resolving api.bookshop.exampleStep 1 of 4
  1. Check the caches

    The browser and operating system check whether they already know the answer from a recent lookup. If so, done.

The trap: you change an A record and some users still reach the old server. Nothing is broken; resolvers are honouring the old TTL. Lower the TTL a day before a planned move so that old answers expire quickly.

Drills

Answer fast — trust the rule.

quick drill

In api.bookshop.example, which part is the top-level domain?

quick drill

Which record maps a name straight to an IPv4 address?

quick drill

You want www.bookshop.example to always go wherever bookshop.example goes. Which record fits?

quick drill

You changed an A record whose TTL was 3600. An hour later, a few users still reach the old server. Why?

quick drill

In which order does a resolver with an empty cache ask servers?

Remember

  • Names are for people; DNS turns them into addresses.
  • Read right to left: that is also the lookup order, root → TLD → authoritative.
  • Answers are cached for their TTL; lower it before a move.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainMoving the bookshop to a new server

The bookshop is moving its API from 203.0.113.10 to 198.51.100.7. Explain which DNS record you change, how a resolver finds the answer, and why some users might keep reaching the old server for a while. What would you do the day before the move?