How DNS Works: Resolvers, Record Types and Troubleshooting
What is DNS?
DNS (Domain Name System) is the distributed directory that translates human-readable names such as example.com into the IP addresses computers use to connect. It also stores records for email routing, domain verification and security policies. A resolver answers each lookup by querying a hierarchy of root, top-level domain and authoritative servers, then caches the answer for a set time.
DNS terminology: resolvers, zones and name servers
- Stub resolver: the small client in your operating system that asks for an answer and waits.
- Recursive resolver: the server, usually run by your ISP, company or a public DNS provider, that does the full lookup on your behalf.
- Root servers: the top of the hierarchy, known by 13 names from a.root-servers.net to m.root-servers.net, each run as many anycast instances.
- TLD servers: servers for top-level domains such as
.com,.organd.in. - Authoritative servers: the servers that hold the actual records for a domain, set by its owner.
- Zone: the portion of the namespace an authoritative server is responsible for, such as
example.com.
DNS queries normally use UDP port 53, with TCP port 53 used for large responses and zone transfers. The TCP/IP guide explains how those transport protocols differ.
How a DNS lookup works: recursive and iterative queries
Your device sends a recursive query to its resolver, meaning "give me the final answer". The resolver then makes iterative queries, where each server replies with either the answer or a referral to the next server to ask.
- The browser and operating system check their own caches and the hosts file.
- If there is no cached answer, the stub resolver asks the recursive resolver for
www.example.com. - The resolver asks a root server, which refers it to the
.comTLD servers. - The TLD server refers it to the authoritative name servers for
example.com. - The authoritative server returns the record, and the resolver caches it and returns it to your device.
Every record carries a TTL (time to live) in seconds. Resolvers and clients may reuse a cached answer until the TTL expires. This is what people call DNS propagation: nothing is pushed around the internet; old answers simply expire from caches at different times. Lowering the TTL a day before a planned change shortens that window.
Common DNS record types
| Record | Purpose | Example value |
|---|---|---|
| A | Maps a name to an IPv4 address | 192.0.2.10 |
| AAAA | Maps a name to an IPv6 address | 2001:db8::10 |
| CNAME | Makes one name an alias of another | www to example.com |
| MX | Names the mail servers for a domain, with a priority | 10 mail.example.com |
| TXT | Free text, used for SPF, DKIM, DMARC and verification | v=spf1 mx -all |
| NS | Lists the authoritative name servers for a zone | ns1.example.net |
| SOA | Start of authority: primary server, contact and timers | Serial, refresh, retry, expire |
| PTR | Reverse lookup from an IP address to a name | 10.2.0.192.in-addr.arpa |
| CAA | Lists which certificate authorities may issue certificates | 0 issue "letsencrypt.org" |
Email authentication lives in TXT records. SPF lists servers allowed to send mail for the domain, DKIM publishes a public key under a selector such as s1._domainkey.example.com, and DMARC at _dmarc.example.com tells receivers what to do when checks fail. These records help defend against spoofing, a topic covered in cybersecurity basics.
example.com. 3600 IN A 192.0.2.10
example.com. 3600 IN AAAA 2001:db8::10
www.example.com. 3600 IN CNAME example.com.
example.com. 3600 IN MX 10 mail.example.com.
example.com. 3600 IN TXT "v=spf1 mx -all"
_dmarc.example.com. 3600 IN TXT "v=DMARC1; p=quarantine; rua=mailto:[email protected]"
example.com. 3600 IN CAA 0 issue "letsencrypt.org" Querying DNS with dig and nslookup
dig is standard on Linux and macOS; nslookup is available on Windows, Linux and macOS. Both let you ask a specific server and see exactly what it returns.
dig example.com A +short # IPv4 address only
dig example.com AAAA # full answer with TTL
dig example.com MX +short # mail servers
dig _dmarc.example.com TXT # DMARC policy
dig @1.1.1.1 example.com # ask a specific resolver
dig +trace example.com # follow root -> TLD -> authoritative
dig -x 192.0.2.10 # reverse (PTR) lookup
nslookup example.com
nslookup -type=mx example.com
nslookup example.com 8.8.8.8Read the ANSWER SECTION for the records and the number before IN for the remaining TTL. The status field shows NOERROR, NXDOMAIN (the name does not exist) or SERVFAIL (the resolver could not get a valid answer).
The hosts file and encrypted DNS
The hosts file maps names to addresses locally and is usually checked before DNS. It lives at /etc/hosts on Linux and macOS and at C:\Windows\System32\drivers\etc\hosts on Windows. It is handy for testing a site on a new server, but a forgotten entry is a common cause of confusing faults, and malware sometimes edits it.
Classic DNS travels unencrypted. DNS over TLS (DoT) uses TCP port 853 and DNS over HTTPS (DoH) uses port 443 to encrypt queries between the client and resolver, which protects them from eavesdropping on the local network. Organisations often run their own encrypted resolver so security filtering and logging still work, as discussed in our network security overview.
Troubleshooting DNS step by step
- Confirm basic connectivity:
pinga known IP address. If that fails, the problem is not DNS. - Check which resolver you are using with
ipconfig /allon Windows orresolvectl statuson Linux systems running systemd-resolved. - Look up the name with
digornslookupand note the status code. - Ask a different resolver and the authoritative server directly; if they disagree, a cache is still holding an old answer.
- Check the hosts file for stale entries.
- Flush the local cache with
ipconfig /flushdnson Windows orresolvectl flush-cacheswith systemd-resolved, then test again.
Practical exercise: trace and document a domain
Choose a domain you own or manage, or use example.com.
- Run
dig +traceand note each root, TLD and authoritative server in the chain. - Query the A, AAAA, MX, NS, TXT, SOA and CAA records and write down each value and TTL.
- Run the same A query twice against your resolver and watch the TTL count down.
- Add a test entry to your hosts file, confirm the browser uses it, then remove it.
You are done when you have a one-page record sheet for the domain and can explain which server answered each step of the trace. DNS labs like this appear in the Networking Foundation course.
Common mistakes
- Blaming DNS before testing whether the target IP address is reachable at all.
- Making a DNS change with a long TTL still in place and expecting it to take effect at once.
- Publishing more than one SPF TXT record for a domain, which makes SPF evaluation fail.
- Leaving test entries in the hosts file after a migration.
- Pointing a CNAME at an IP address instead of a hostname.
Frequently asked questions
Why does a website load for my colleague but not for me after a DNS change?
You are probably using different resolvers, and yours still has the old answer cached until its TTL runs out. Flushing your local cache helps only if the resolver itself has already expired the record.
Is DNS part of the application layer?
Yes. DNS is an application-layer protocol that runs over UDP and TCP. The OSI model explained shows where it sits alongside HTTP and SMTP.
What does NXDOMAIN mean?
It means the authoritative server says the name does not exist. Check the spelling, the zone and whether the record was ever created.