Debug DNS with dig and nslookup, Step by Step
A teammate says the new shop page "can't be reached", yet every other site loads. Lesson 3 showed that this smells like DNS; this lesson shows how to prove it with dig and nslookup. You will read every part of a DNS reply, choose which server to ask, follow a name down from the root, and fix the two most common faults.
nslookup or dig: same question, different detail
Both tools send one DNS question and print the reply. nslookup, which you met in lesson 3's try-it, is built into Windows, macOS and most Linux systems. It prints a short summary: the server it asked, then names and addresses.
dig ("domain information groper") prints the whole reply: a status code, flags, every section, the TTL of each record, which server answered and how long it took. It comes with macOS and, on Linux, with the BIND tools (bind9-dnsutils on Debian and Ubuntu). Windows lacks it, so the lab gives you a Linux shell. In nslookup, -type=mx picks the record type and a second argument names the server to ask: nslookup -type=mx gmail.com 8.8.8.8.
Reading dig output: status, answer, TTL and server
Here is dig example.com in the lab shell. Lines about EDNS, an extension that lets DNS messages carry more data, are trimmed. The address, TTL and times are illustrative, and the real example.com returns several A lines:
; <<>> DiG 9.20.29-1~deb13u1-Debian <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31517
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 300 IN A 203.0.113.7
;; Query time: 14 msec
;; SERVER: 127.0.0.11#53(127.0.0.11) (UDP)
;; WHEN: Tue Dec 01 10:15:42 UTC 2026
;; MSG SIZE rcvd: 56
The header comes first. status is the result: NOERROR means the lookup worked, NXDOMAIN that the name does not exist, SERVFAIL that the server could not get an answer, and REFUSED that it will not answer you.
The flags say how the reply was made: qr marks a reply, rd (recursion desired) means you asked the server to do the whole search, and ra (recursion available) means it offers to. aa (authoritative answer) appears only when the domain's own server replies. An ad flag means your resolver checked the records' DNSSEC signatures, which prove they are genuine.
The question section repeats what you asked: the name, the class IN (internet, nearly always) and the type. The answer section holds one record per line: name, TTL in seconds, class, type and data. In a resolver's cache the TTL counts down, so a number below the owner's setting means a saved copy answered.
The footer shows the time taken and, on the SERVER line, who answered: address, port 53 and UDP. In the lab that is 127.0.0.11, Docker's built-in DNS server, which passes questions on to your laptop's resolver.
Useful flags: +short, record types and @server
+short prints only the data, a type such as MX picks the record to ask for (A is the default), and @ names the server to ask:
$ dig +short MX gmail.com
5 gmail-smtp-in.l.google.com.
10 alt1.gmail-smtp-in.l.google.com.
20 alt2.gmail-smtp-in.l.google.com.
30 alt3.gmail-smtp-in.l.google.com.
40 alt4.gmail-smtp-in.l.google.com.
Each MX line gives a priority and a mail server; lower numbers are tried first. The lines may come in any order, and the trailing dot marks a complete name that ends at the root.
dig example.com @8.8.8.8 skips your usual resolver and asks Google Public DNS, so the footer says SERVER: 8.8.8.8#53(8.8.8.8). Comparing two resolvers is the quickest way to tell a broken resolver from a broken name.
NS (name server) records list a domain's own servers: dig +short NS example.com prints their names. dig example.com @a.iana-servers.net then returns the owner's current entry with the aa flag, from no one's cache.
dig +trace: follow the chain from the root
Lesson 3 described the resolver's walk from the root to the authoritative server. dig +trace example.com makes that walk visible: it turns recursion off, asks each server itself and prints every reply.
Here is the real output, trimmed: most NS lines are cut, as are the DNSSEC lines (DS and RRSIG) that +trace asks for. The final address, TTLs, byte counts and times are illustrative, and your trace may reach other root and .com servers:
. 518400 IN NS a.root-servers.net.
;; Received 525 bytes from 127.0.0.11#53(127.0.0.11) in 3 ms
com. 172800 IN NS a.gtld-servers.net.
;; Received 1170 bytes from 198.41.0.4#53(a.root-servers.net) in 20 ms
example.com. 172800 IN NS a.iana-servers.net.
;; Received 268 bytes from 192.5.6.30#53(a.gtld-servers.net) in 24 ms
example.com. 300 IN A 203.0.113.7
;; Received 98 bytes from 199.43.135.53#53(a.iana-servers.net) in 80 ms
Read each Received line as one step: who replied, and how fast. A trace that stalls or times out at one level shows where the chain breaks, such as name servers that no longer answer. The last answer comes from the domain's own server, not a cache, so a trace shows what the owner publishes now.
Typical fixes: NXDOMAIN and resolvers that disagree
When a site will not load, the flowchart starts with one question: does dig +short print an address?
+short hides the reason; the full dig's status names it.NXDOMAIN means DNS says the name does not exist, so first check the spelling. If it is right, ask the domain's own server with @: NXDOMAIN there too means the owner has not created the name. Resolvers also remember an NXDOMAIN for a while, so a name added minutes ago may still fail. NOERROR with ANSWER: 0 differs: the name exists but has no record of that type.
If two resolvers disagree, one usually holds an old copy: after a change, each keeps the previous answer until its TTL runs out, the propagation delay from lesson 3. The TTL it shows is about how many seconds remain before it fetches the new entry. Some sites answer differently on purpose, sending each resolver to a nearby server, as CDNs do (lesson 17).
SERVFAIL or a timeout from your resolver alone points at it or your network: switch to @1.1.1.1. SERVFAIL from every resolver points at the domain's own servers; +trace shows where the chain stops. If the address matches the domain's own server, DNS is fine: test it with curl (lesson 21).
Check yourself
dig +short shop.example.com prints nothing, but dig +short example.com prints an address. What should you run next?
The full dig shop.example.com, to read the status. Empty +short output can mean NXDOMAIN, SERVFAIL or no A record, and each needs a different fix.
After you change an A record, your resolver still returns the old address, but the domain's own server returns the new one. Is the change broken?
No. The authoritative answer is right; your resolver is serving a saved copy until its TTL runs out, the usual propagation delay.
In dig +trace output, the root server's reply holds no A record for example.com. Why not?
Root servers only know who runs each top-level domain, so they send a referral: the NS records of the .com servers, one level down.