Skip to content
DNS

· 5 min read

What is DNS and how does a DNS lookup work?

DNS is the internet's phone book: it turns a name a person can remember into the address a computer needs. Every page load starts with a lookup. This guide follows one, step by step, and shows you how to run your own.

On this page

What DNS does#

Computers route traffic by IP address, and people remember names. The Domain Name System is the distributed database that connects the two. You type www.example.com, your device asks DNS what address that name has, and only then can it open a connection. Nearly every page load, app request and email delivery starts with at least one lookup.

No single computer holds the whole database. Names are arranged in a hierarchy that reads right to left: the root, then a top-level domain such as .com, then the domain someone registered, example, then whatever they add on the left, such as www. Each level is run by a different party, and each one knows only who is responsible for the level below. That is what lets the system scale to hundreds of millions of names with no central list.

How a DNS lookup works#

How a DNS lookup resolves a nameStep 1: the browser asks its resolver for the address of a name. Step 2: the resolver asks a root server, which points it to the .com servers. Step 3: the resolver asks a .com server, which points it to the authoritative servers of the domain. Step 4: the resolver asks the authoritative server and gets the address. Step 5: the resolver returns the answer to the browser and keeps a copy for the time to live of the record.BrowserResolverRoot.comAuthoritative12345
Solid arrows are questions, dashed arrows are answers. Numbers match the steps below.
  1. Your device asks its resolver. The browser and operating system first check their own caches. If the answer is not there, they ask a recursive resolver: usually your ISP's, or a public one you chose, such as 1.1.1.1 or 8.8.8.8.
  2. The resolver asks a root server. It does not know example.com, but it knows how to reach the root servers, which know who runs each top-level domain. The root replies with a referral to the .com servers, not with the answer.
  3. The resolver asks a `.com` server. That server does not hold the record either. It knows which authoritative name servers the owner of example.com chose, and says so.
  4. The resolver asks the authoritative server. This is the one place the actual record lives, so this time the reply is the answer: an address, such as 203.0.113.10.
  5. The resolver answers you, and remembers. It returns the address and keeps a copy for as long as the record's time to live allows. The next person to ask gets the cached copy in milliseconds.

There are 13 root server addresses, named a.root-servers.net to m.root-servers.net. Each is served by many machines around the world using anycast, so there are far more than 13 physical servers. IANA publishes the list.

The record types you will meet#

Common DNS record types
TypeWhat it holdsExample
AAn IPv4 address for a nameexample.com → 203.0.113.10
AAAAAn IPv6 address for a nameexample.com → 2001:db8::10
CNAMEAn alias: this name is really that other namewww.example.com → example.com
MXThe mail servers for a domain, with a priority. Lower numbers are tried first10 mail.example.com
NSThe authoritative name servers for a domainns1.example.net
TXTFree text. Used for SPF and DKIM email policy and for proving you own a domain"v=spf1 include:_spf.example.net -all"
SOAAdministrative data for a zone: primary server, contact, serial number, refresh timersns1.example.net hostmaster.example.com 2026092501 …
CAAWhich certificate authorities may issue certificates for the domain0 issue "letsencrypt.org"
PTRThe name for an address: reverse DNS, stored under in-addr.arpa or ip6.arpa42.113.0.203.in-addr.arpa → host.example.com

All of these can be queried with the DNS lookup tool. The addresses shown are from the documentation ranges.

PTR records work the other way round and are managed by whoever owns the address, not the domain: see reverse DNS.

Run a DNS lookup yourself#

The quickest way is the DNS lookup tool: type a domain, choose a record type or all of them, and read the answers with their TTLs. The same query from a terminal:

The same lookup, four ways
dig example.com A +short          # Linux, macOS
dig example.com MX
nslookup -type=MX example.com     # Windows, macOS, Linux
Resolve-DnsName example.com -Type A   # PowerShell

To follow the chain in the diagram, dig +trace example.com asks the root, then the top-level servers, then the authoritative servers directly, and prints every step.

DNS and privacy#

Every name you look up goes to your resolver, which therefore sees a list of the sites you visit even when the connections themselves are encrypted. Plain DNS is also unencrypted, so anyone on the path can read it and, in some networks, alter it.

  • Encrypted DNS hides the queries from the network between you and the resolver. DNS over HTTPS (RFC 8484) and DNS over TLS both do this. Browsers and operating systems now support them.
  • Your choice of resolver decides who sees the list. Your ISP's resolver, a public one such as Cloudflare's, Google's or Quad9's, and a resolver run by your VPN each have different policies. Read the one you use.
  • A DNS leak is when a VPN is connected but DNS queries still go to your ISP's resolver, so the ISP can see every name you look up. The leak test checks for it.

Common questions#

What is the difference between a recursive and an authoritative server?

An authoritative server holds the records for a domain and answers only for it. A recursive resolver holds none, and does the work of asking the authoritative servers on your behalf, then caches what it learns.

Why can two people get different answers for the same name?

Because of caching with different TTLs, because large sites return different addresses by location or load, and because some resolvers filter or rewrite answers.

Is DNS the same as a domain registrar?

No. A registrar sells you the name and records who owns it. DNS hosting is where the records that the name points to are stored. They are often the same company and are still separate jobs.

Try it on your own connection

Sources and further reading

Keep reading

Published by My IP Address