DNS: how names become addresses
Follow a real lookup from the root servers down to the answer, read the record types you will use, and learn why DNS changes take time and how to make them safely.
By the end of this lesson you'll be able to
0 of 4 completeVerified lab: every lookup below was made with dig against real public DNS (root servers, .com servers,
Cloudflare, Google and Cloudflare public resolvers). The output shown is real.
Cloud lab: none needed.
"It's always DNS" is a joke because it's so often true: a wrong record, a stale cache or a missing resolver looks like "the site is down". This lesson makes DNS something you can check in seconds.
Root, then .com, then the answer
You can walk the same chain by hand. +norecurse asks each server only what it knows itself:
$ dig @a.root-servers.net com NS +norecurse +noall +authority com. 172800 IN NS l.gtld-servers.net. com. 172800 IN NS j.gtld-servers.net. ... $ dig @a.gtld-servers.net example.com NS +norecurse +noall +authority example.com. 172800 IN NS hera.ns.cloudflare.com. example.com. 172800 IN NS elliott.ns.cloudflare.com. $ dig @hera.ns.cloudflare.com example.com A +norecurse +noall +answer example.com. 300 IN A 104.20.23.154 example.com. 300 IN A 172.66.147.243
The root doesn't know example.com, but knows who runs .com. The .com servers know who runs example.com
(Cloudflare). Cloudflare's server is authoritative: it holds the real records. Your resolver does this walk once
and then caches each step, so the next lookup is one hop.
Record types
$ dig github.com MX +short 0 github-com.mail.protection.outlook.com. $ dig github.com NS +short dns1.p08.nsone.net. ... ns-421.awsdns-52.com.
GitHub runs its DNS on two providers at once (NS1 and Route 53), so one provider's outage doesn't take the name down. When a name doesn't exist at all, the status says so:
$ dig no-such-domain-xq7z1.com A | grep status ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 58160
dig no-such-domain-xq7z1.com A | grep status|pipe: send output to the next commandgrepfind lines that match a pattern
NXDOMAIN is "no such name". NOERROR with no answer means the name exists but has no record of that type.
SERVFAIL means the resolver couldn't get an answer, often a broken delegation or DNSSEC problem.
TTL and caching
$ dig @8.8.8.8 example.com A +noall +answer example.com. 282 IN A 172.66.147.243 $ dig @1.1.1.1 example.com A +noall +answer example.com. 23 IN A 104.20.23.154
The second column is the time left in that resolver's cache. Google had 282 of 300 seconds left, Cloudflare 23. Both are correct; they just cached at different moments. That's all "DNS propagation" is.
Resolvers on Linux
$ grep hosts /etc/nsswitch.conf hosts: files dns $ cat /etc/resolv.conf nameserver 10.255.255.254 search lan
grep hosts /etc/nsswitch.confgrepfind lines that match a pattern
cat /etc/resolv.confcatprint a file
files dns means: check /etc/hosts first, then ask the nameserver in /etc/resolv.conf (WSL's resolver here;
on a VPC server it's the VPC's .2 address). search lan appends .lan to short names. Two things to remember:
an entry in /etc/hosts beats DNS (great for testing, terrible when forgotten), and dig skips /etc/hosts while
getent hosts name follows the same order your apps do.
Kubernetes runs its own DNS (CoreDNS), so orders.shop.svc.cluster.local resolves inside the cluster. A Pod's
resolv.conf has several search domains and ndots:5, which is why lookups of external names can be slow: each
short name is tried with every search suffix first. AWS course lesson 8 covers Route 53.
Trace a domain you use
Pick a domain you use at work or for a project. Walk its lookup from a root server, list its A, AAAA, MX, NS and TXT records, compare the TTL from two public resolvers, and note which resolver your own machine uses.
~/dns.txtReveal one safe solution
$ D=github.com $ dig @a.root-servers.net ${D##*.} NS +norecurse +noall +authority | head -2 > ~/dns.txt $ for t in A AAAA MX NS TXT; do echo "== $t"; dig $D $t +short; done >> ~/dns.txt $ dig @8.8.8.8 $D A +noall +answer >> ~/dns.txt; dig @1.1.1.1 $D A +noall +answer >> ~/dns.txt $ grep nameserver /etc/resolv.conf >> ~/dns.txt
dig @a.root-servers.net ${D##*.} NS +norecurse +noall +authority | head -2 > ~/dns.txt|pipe: send output to the next commandheadshow the first lines>write output to a file, replacing it
for t in A AAAA MX NS TXT; do echo "== $t"; dig $D $t +short; done >> ~/dns.txtforloop over a listdostart of what the loop runs each timeechoprint textdoneend of the loop>>append output to a file
grep nameserver /etc/resolv.conf >> ~/dns.txtgrepfind lines that match a pattern
Then follow the name servers from the first step down to an authoritative answer yourself.
Try it yourself
0 of 5 steps doneRun each task in your own account or terminal, then tick it off.
Quick check
You changed an A record ten minutes ago and some users still reach the old server. Why?
Official reading for this lesson
Or get every quiz answer right and it completes itself.
Something unclear, wrong or out of date in this lesson? Tell me, and I'll fix it.