beginner

DNS: How Names Become Addresses

The internet's phone book: how a domain name is resolved step by step, the common record types, caching and TTL, and how to test and troubleshoot DNS with nslookup and dig.

30 min

Why DNS exists

People remember names (learn.example.com); networks route addresses (203.0.113.25). The Domain Name System (DNS) translates one into the other. It is a distributed, hierarchical database: no single computer holds all the names. DNS is so central that when it fails, “the internet is down” even though everything else works.

The name hierarchy

A name such as www.example.com. is read right to left. The final (usually invisible) dot is the root.

  • Root (.): 13 named root server systems, operated by different organisations and replicated at many sites worldwide.
  • Top-level domain (TLD): com, org, ng, uk, and so on.
  • Second-level domain: example, the part you register.
  • Subdomain / host: www, mail, and so on, which the domain owner creates freely.

The servers that hold the real records for a domain are its authoritative name servers.

How a lookup works

Your device does not walk the hierarchy itself. It asks a recursive resolver, usually run by your ISP, your organisation, or a public provider, whose address came from DHCP or manual configuration. The resolver does the work:

sequenceDiagram participant PC as Your PC participant R as Recursive resolver participant Root as Root server participant TLD as .com server participant Auth as example.com authoritative PC->>R: www.example.com ? R->>Root: www.example.com ? Root->>R: Ask the .com servers R->>TLD: www.example.com ? TLD->>R: Ask example.com's servers R->>Auth: www.example.com ? Auth->>R: 203.0.113.25 (TTL 300) R->>PC: 203.0.113.25
  1. The PC checks its own cache and the local hosts file first, then asks the resolver.
  2. If the resolver has no cached answer, it asks a root server, which does not know the answer but refers it to the servers for the TLD.
  3. The TLD server refers it to the domain’s authoritative servers.
  4. The authoritative server gives the answer.
  5. The resolver caches the answer for the time the record allows and returns it to the PC.

Queries normally use UDP port 53 and fall back to TCP for large responses.

Caching and TTL

Every record has a TTL in seconds, set by the domain owner. Caches keep the answer until it expires, which makes DNS fast and spreads the load. The downside: when you change a record, old answers linger until their TTL runs out. Before a planned migration, lower the TTL (to a few minutes) a day or two ahead, make the change, then raise it again.

Common record types

Type Purpose Example
A Name to IPv4 address www A 203.0.113.25
AAAA Name to IPv6 address www AAAA 2001:db8::25
CNAME Alias to another name (cannot sit at the zone apex) blog CNAME www.example.com.
MX Mail servers for the domain, with priority @ MX 10 mail.example.com.
NS Authoritative name servers for the zone @ NS ns1.example.net.
TXT Free text, used for SPF, DKIM, domain verification @ TXT "v=spf1 include:..."
PTR Reverse lookup: IP address to name 25.113.0.203.in-addr.arpa PTR www.example.com.
SOA Zone administration data (serial, timers) one per zone

Testing DNS

nslookup www.example.com            # Windows, Linux, macOS
nslookup www.example.com 8.8.8.8    # ask a specific resolver

dig www.example.com                 # Linux/macOS (more detail)
dig +short MX example.com
dig @8.8.8.8 www.example.com AAAA
dig +trace www.example.com          # follow the hierarchy from the root
Resolve-DnsName www.example.com -Type A
Get-DnsClientServerAddress          # which resolvers you use
ipconfig /flushdns                  # clear the Windows cache

How to read a result: note the server that answered, the answer section (the records), and the TTL. A status of NXDOMAIN means the name does not exist; SERVFAIL means the resolver could not complete the lookup (often a problem at the authoritative side); a timeout means the resolver itself was unreachable.

Troubleshooting DNS

  1. Does the IP address work? If ping 8.8.8.8 works but names do not, it is DNS.
  2. Which resolver are you using? (ipconfig /all, resolvectl status). Is it the one you expect?
  3. Ask a different resolver, for example nslookup name 1.1.1.1. If that works, the first resolver is at fault.
  4. Check the cache: flush it, then retry. A stale entry is common after a change.
  5. Check the authoritative servers: use dig NS example.com then ask them directly with dig @ns1.example.net example.com. If they disagree with the resolver, the answer is cached or the delegation is wrong.
  6. Look for the hosts file (/etc/hosts, C:\Windows\System32\drivers\etc\hosts) overriding names.
You moved your website to a new server and updated the A record. A colleague still sees the old site, but your phone on mobile data sees the new one. Give two possible reasons and what you would do.

Their computer or their resolver is serving a cached copy of the old record until its TTL expires (the phone used a different resolver that already refreshed), or their hosts file overrides the name. Flush the colleague’s DNS cache, ask a different resolver with nslookup/dig, check the TTL you had set, and check for a hosts file entry.

Can You Explain It?

Close the lesson and answer these without looking back. The goal isn't the wording — it's whether you've formed a usable mental model.

  • Describe in order what happens between typing a name in a browser and the browser learning the IP address, for a name nobody has looked up recently.
  • What is the difference between a recursive resolver and an authoritative server?
  • Why can a DNS change take hours to reach all users, and how do you reduce the delay?

🧪 Want to practise this on your own computer? See how to set up your lab →

🤖

Need clarification? Ask GT

Hi, I'm GT — your AI tutor for DNS: How Names Become Addresses. What would you like to know?
📝

Knowledge Check

1 of 4

Which DNS record type maps a name to an IPv4 address?

Report a problem

About: /lessons/dns-how-names-become-addresses