· 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#
- 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.1or8.8.8.8. - 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.comservers, not with the answer. - The resolver asks a `.com` server. That server does not hold the record either. It knows which authoritative name servers the owner of
example.comchose, and says so. - 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. - 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#
| Type | What it holds | Example |
|---|---|---|
A | An IPv4 address for a name | example.com → 203.0.113.10 |
AAAA | An IPv6 address for a name | example.com → 2001:db8::10 |
CNAME | An alias: this name is really that other name | www.example.com → example.com |
MX | The mail servers for a domain, with a priority. Lower numbers are tried first | 10 mail.example.com |
NS | The authoritative name servers for a domain | ns1.example.net |
TXT | Free text. Used for SPF and DKIM email policy and for proving you own a domain | "v=spf1 include:_spf.example.net -all" |
SOA | Administrative data for a zone: primary server, contact, serial number, refresh timers | ns1.example.net hostmaster.example.com 2026092501 … |
CAA | Which certificate authorities may issue certificates for the domain | 0 issue "letsencrypt.org" |
PTR | The name for an address: reverse DNS, stored under in-addr.arpa or ip6.arpa | 42.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:
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 # PowerShellTo 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
- DNSReverse DNS and PTR recordsReverse DNS maps an IP address back to a hostname using PTR records. How the in-addr.arpa lookup works, why mail servers check it, and how to run one.
- FundamentalsWhat is an IP address?An IP address is the label that lets devices find each other on a network. What one looks like, who assigns it, and what it can and cannot reveal about you.
- FundamentalsA beginner's guide to networkingHow devices talk to each other: layers, addresses, ports, routers, DHCP and DNS, and what really happens between typing a web address and seeing the page.
- PrivacyHow websites see your IP addressEvery site you visit receives your public IP address. Where it comes from, how proxies and CDNs pass it along, what else is sent with it, and what a VPN changes.
Published by My IP Address