Lesson 3 of 14 · 10 min · How networks work
DNS: how names become addresses
What you will learn
- What DNS is and the roles of the different DNS servers
- The steps of a lookup, and where caching happens
- The record types you meet in DevOps work: A, AAAA, CNAME, MX, TXT, NS, PTR
- TTL, and why DNS changes "take time"
In simple words
Computers find each other by number, but people remember names. DNS is the internet's phone book: you give it a name such as myskillgrid.com and it returns the number to call. This lesson shows who keeps that phone book, how a lookup travels, and why a change takes time to reach everyone.
Words to know
- DNS: the system that turns names into IP addresses.
- Resolver: the server that looks a name up for you and remembers the answer for a while.
- Record: one entry in the phone book. An A record maps a name to an IP address.
- TTL: time to live: how long an answer may be remembered before it is asked for again.
Why DNS exists
Computers route by IP address; people remember names. DNS (Domain Name System) is a worldwide, distributed database that maps names like example.com to data, mostly IP addresses. No single server holds it all. It is organised as a tree of zones, each run by whoever owns that part of the name.
A name is read right to left. In www.example.com. (the final dot is the invisible root):
. root
com top-level domain (TLD)
example the domain you register
www a name inside your zone (a subdomain or host)
Who does what
| Role | What it does |
|---|---|
| Stub resolver | The small client in your OS or application. Asks the configured resolver and caches. /etc/resolv.conf or systemd-resolved configures it |
| Recursive resolver | A server (your ISP's, your company's, or public ones like 1.1.1.1 or 8.8.8.8) that does the work of finding the answer, and caches it for everyone using it |
| Root servers | Know which servers are responsible for each TLD (.com, .in, .org). 13 named server sets, each replicated worldwide |
| TLD servers | Know which servers are responsible for each domain under the TLD |
| Authoritative servers | Hold the actual records for a zone. These are the servers you configure at Route 53, Cloudflare or your registrar |
A lookup step by step
For www.example.com with nothing cached:
- The application asks the OS. The OS checks
/etc/hosts, then its cache, then asks the recursive resolver. - The resolver asks a root server: "who handles
.com?" It answers with the.comTLD servers (a referral). - The resolver asks a
.comserver: "who handlesexample.com?" It answers with the domain's name servers. - The resolver asks the authoritative server: "what is the A record of
www.example.com?" It answers with the IP address. - The resolver returns the answer and caches it for the record's TTL; your OS caches it too.
dig +trace performs these steps itself and shows each referral. The first lines of its real output show the root servers:
. IN NS f.root-servers.net.
. IN NS g.root-servers.net.
. IN NS h.root-servers.net.
The usual transport is UDP port 53 (small, fast); DNS switches to TCP port 53 for large answers, zone transfers, and in DNS-over-TLS (port 853) or DNS-over-HTTPS.
Record types
dig example.com NS +short
dig example.com TXT +short
dig www.github.com CNAME +short
dig -x 1.1.1.1 +short
Real answers when we ran them:
elliott.ns.cloudflare.com.
hera.ns.cloudflare.com.
"v=spf1 -all"
github.com.
one.one.one.one.
| Type | Maps | Notes |
|---|---|---|
| A | name → IPv4 address | the most common |
| AAAA | name → IPv6 address | "quad-A" |
| CNAME | name → another name (an alias) | the resolver then looks up the target. Not allowed at the zone apex (example.com itself); clouds offer "alias" records for that |
| MX | domain → mail servers, with priority | lower number is preferred. 0 . is a "null MX": the domain accepts no mail |
| TXT | name → free text | used for SPF/DKIM/DMARC email policy, domain-ownership checks (the long random string above) |
| NS | zone → its authoritative name servers | set at the registrar to delegate a domain |
| PTR | IP → name (reverse DNS) | lookups under in-addr.arpa; dig -x |
| SOA | zone's administrative data | serial number, refresh and negative-cache times |
| SRV | service → host and port | used by some protocols and by service discovery |
TTL and caching
Every record carries a TTL (time to live) in seconds: how long caches may keep it. In the dig answer earlier the second column showed 278 for example.com: that cache would serve the answer for 278 more seconds.
This is why DNS changes "propagate slowly": there is no push. Old answers live in caches until their TTL runs out. Practical consequences:
- Before a planned migration, lower the TTL (for example to 60 seconds) a day ahead. After the change is stable, raise it again.
- A very low TTL means more queries and more latency; a very high TTL means slow recovery. 300 to 3600 seconds is typical.
- Negative caching: "this name does not exist" (
NXDOMAIN) is cached too, using the SOA's value. If you query a name before creating it, that failure may be cached for a while. - Clients such as browsers, the JVM and some libraries cache on their own, sometimes ignoring TTL. A restart clears them.
DNS in your infrastructure
- Public zones (Route 53, Cloudflare DNS, GoDaddy) hold your internet-facing records; private zones hold internal names visible only inside a VPC.
- Kubernetes runs its own DNS (CoreDNS) so that Services get names like
my-svc.my-namespace.svc.cluster.local. - Load balancers and CDNs are reached through CNAME or alias records to names like
my-lb-123.ap-south-1.elb.amazonaws.com, whose IP addresses change. That is why you point to the name, never to an IP you looked up. - Email depends on DNS: wrong MX or missing SPF/DKIM records send mail to spam or lose it.
- DNS is a favourite cause of outages ("it's always DNS"): a deleted record, expired domain, wrong NS delegation, or a resolver that cannot be reached.
Common mistakes
- Expecting a DNS change to be instant or testing it from a machine with the old answer cached.
- CNAME at the apex, or a CNAME alongside other records of the same name (not allowed).
- Hard-coding IPs of load balancers or cloud services.
- Forgetting the trailing details of delegation: NS records at the registrar must match the zone you actually edit.
- Blaming the application when
getent hosts namefails.
Try it yourself
- Run
dig +tracefor a domain you know and mark the root, TLD and authoritative steps. - Find the NS, MX and TXT records of a domain of your choice, and say what each tells you.
- Run
digtwice and watch the TTL count down. Then query a different resolver withdig @1.1.1.1 nameand compare. - Check
cat /etc/resolv.confandresolvectl status(if available) to see which resolver your machine uses.
Check yourself
What is the difference between a recursive resolver and an authoritative server?
A recursive resolver looks up answers for clients by asking other servers and caches them. An authoritative server holds the real records for a zone and answers only for that zone.
Why does a DNS change not take effect everywhere at once?
Resolvers and clients cache answers for the TTL. Until the old entry expires, they keep returning it. Lower the TTL before a planned change.
What is the difference between an A record and a CNAME?
An A record maps a name to an IPv4 address. A CNAME maps a name to another name, which is then resolved.
Which transport does DNS use?
Mostly UDP on port 53; TCP on port 53 for large responses and zone transfers; also TLS (853) and HTTPS for encrypted DNS.
Interview questions
Explain how a DNS lookup works.
The stub resolver asks the recursive resolver. If it has no cached answer it asks a root server for the TLD servers, a TLD server for the domain's name servers, and the authoritative server for the record, then caches and returns the answer for the TTL.
A website works for some users but not for others right after you moved it to a new IP. Why?
Some resolvers still hold the old record in cache until the TTL expires. Check with dig @resolver; avoid the problem by lowering the TTL before changes.
What DNS records does email need?
MX records to route mail, plus TXT records for SPF, DKIM and DMARC to prove the sender is legitimate; PTR records for the sending server's reverse DNS also matter.
Summary
- DNS is a distributed, cached hierarchy: stub resolver → recursive resolver → root → TLD → authoritative.
- Know A, AAAA, CNAME, MX, TXT, NS, PTR; CNAME cannot sit at the apex.
- TTL controls caching; lower it before changes and expect delay; NXDOMAIN is cached too.
- Always point at names, never at looked-up IPs of managed services.
Going deeper
- RFC 1034: Domain Names, concepts and facilities: the original concepts of DNS.
- RFC 1035: Domain Names, implementation and specification: the protocol and record formats.
- IANA: Root Servers: the authoritative list of root and TLD information.
- Amazon Route 53: supported record types: record types in a managed DNS service.
See how much of this you can explain
A free mock interview asks you new questions on Networking for DevOps for DevOps Engineer and scores every answer, with what to fix.