Using nslookup and dig to Debug DNS
Learn the nslookup and dig commands that answer real DNS questions, how to read the output and a method for finding the fault.
Key takeaways
- Always note which server answered, because your configured resolver and the authoritative server can disagree.
- Query the record type you care about, such as MX or TXT, since the default asks only for addresses.
- The status code in
digoutput distinguishes a missing name from a server failure or a refusal. - Comparing a cached answer with an authoritative one shows whether you have a wrong record or just an old copy.
nslookup and dig let you ask DNS servers questions directly, bypassing the browser. With them you can see which address a name returns, which server said so, how long the answer will be cached and where a lookup goes wrong. nslookup is already on Windows and macOS. dig gives fuller, clearer output and is the better tool when you have it.
This guide covers the commands you'll use most, how to read the results and a routine for tracking down a DNS fault.
Getting the tools
Windows: nslookup is built in. PowerShell also offers Resolve-DnsName. For dig, install the BIND utilities or use the Windows Subsystem for Linux.
macOS: both commands are typically included.
Linux: install the package that provides them, commonly named dnsutils or bind-utils depending on the distribution.
nslookup basics
The simplest form looks up addresses using your default resolver:
nslookup example.com The first lines name the server that answered. The lines after give the result. "Non-authoritative answer" is normal: it means the reply came from a resolver and not from the domain's own name server.
Ask for other types, or ask a different server:
nslookup -type=mx example.com
nslookup -type=txt example.com
nslookup -type=ns example.com
nslookup example.com 1.1.1.1 Look up an address in reverse:
nslookup 192.0.2.25 Running nslookup alone starts an interactive mode, where server 8.8.8.8 changes the target and set type=mx changes the question. exit leaves.
The PowerShell equivalent returns structured results, which suits scripts:
Resolve-DnsName example.com -Type MX
Resolve-DnsName example.com -Server 1.1.1.1 dig basics
dig example.com
dig example.com AAAA
dig example.com MX +short
dig @1.1.1.1 example.com TXT
dig -x 192.0.2.25 The @ picks the server, a type name picks the record and +short prints only the data. Without +short you get several sections.
Reading nslookup output
A typical reply looks like this, again with illustrative values:
Server: router.home.arpa
Address: 192.168.1.1
Non-authoritative answer:
Name: example.com
Addresses: 2001:db8::10
192.0.2.10 The first block identifies the resolver that was asked. If the server name shows as unknown, that usually just means there's no reverse record for the resolver's address, and the lookup itself may be fine.
| Message | Likely meaning |
|---|---|
| Non-existent domain | The name doesn't exist, as far as that server knows |
| Server failed | The resolver couldn't get a valid answer |
| Query refused | That server won't serve your request |
| DNS request timed out | No reply arrived in time |
| Name only, no address | The name exists but has no record of that type |
For more detail, -debug prints the full reply, including flags and TTL values:
nslookup -debug example.com If a Windows lookup shows extra queries with your network's domain appended, that's the suffix search list at work. The trailing dot avoids it.
Reading dig output
A full reply includes a header, the question, then sections for answer, authority and additional data, and finally timing and the server used.
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4821
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; ANSWER SECTION:
example.com. 287 IN A 192.0.2.10 This sample is illustrative. In the answer line, 287 is the remaining TTL in seconds, IN is the internet class, A the type and the last field the data. From a caching resolver the TTL counts down on repeated queries.
The status tells you what happened:
| Status | Meaning | Look at |
|---|---|---|
NOERROR | The query succeeded; an empty answer means no record of that type | Type and spelling |
NXDOMAIN | The name doesn't exist | Typo, missing record or expired domain |
SERVFAIL | The server couldn't produce an answer | Broken delegation, DNSSEC or unreachable servers |
REFUSED | The server won't answer you | Wrong server or access rules |
| Timeout | No reply at all | Network path, firewall or dead server |
More detail is in NXDOMAIN, SERVFAIL and other errors.
Useful flags: aa means the answer is authoritative, rd means recursion was requested, ra means the server offers recursion and ad means a validating resolver authenticated the data with DNSSEC.
Asking the authoritative server
This is the most useful habit in DNS debugging. Find who is authoritative, then ask them.
dig example.com NS +short
dig @ns1.example.net example.com A +norecurse Substitute a name from the first output into the second. The reply should carry the aa flag. If it shows your new value while resolvers show the old one, the change is published and caches haven't expired. If it shows the old value, the record was never updated where it counts, perhaps because you edited a zone at a provider the domain doesn't use. See recursive and authoritative servers.
Check every listed name server, since they can fall out of step. Comparing the serial number in the SOA record is a quick test:
dig @ns1.example.net example.com SOA +short
dig @ns2.example.net example.com SOA +short Some managed DNS services don't use serials in the traditional way, so compare the records themselves if the numbers look odd.
Following the delegation
dig +trace example.com With +trace, dig starts at the root servers and follows each referral itself: root, then top-level domain, then your name servers. Where the chain stops or points somewhere unexpected, you've found your problem. Some networks block direct queries to outside DNS servers, in which case the trace fails for reasons unrelated to the domain.
Common investigations
Mail isn't arriving. Query MX, then the addresses of each host it names. Check the SPF record with a TXT query, and DMARC at _dmarc.example.com:
dig example.com MX +short
dig example.com TXT +short
dig _dmarc.example.com TXT +short A subdomain alias is wrong. Query it and look for the chain of CNAMEs in the answer section. Each target must resolve in turn.
DNSSEC is suspected. If a query returns SERVFAIL, repeat it with +cd, which asks the resolver to skip validation:
dig example.com A
dig example.com A +cd An answer only with +cd points to a signing or DS record problem. Use +dnssec to see signature records. This is for diagnosis; the fix is to correct the signing, as described in DNSSEC explained.
Large answers fail. Add +tcp to force TCP. If TCP works and ordinary queries don't, something on the path may be mishandling large UDP packets.
Worked example: a site works for some people
Say you moved www.example.com to a new server this morning. You see the new site, and a colleague still sees the old one.
First, ask the authoritative server for the A and AAAA records. Suppose the A record shows the new address, but the AAAA record still shows the old IPv6 address. People whose networks prefer IPv6 would reach the old machine, which explains the split.
Fix the AAAA record, then check each authoritative server again. Next, query a couple of public resolvers and read the remaining TTL to estimate when the old answer will disappear. Finally, ask the colleague to run the same query and send you the output, including the server line. If their resolver is a company filter or an internal DNS server with its own copy of the zone, you'll see it there.
Had the authoritative servers shown correct values for both types, the next suspects would be the browser cache, a hosts file entry on that computer or an intermediate proxy.
Asking for help with useful evidence
When you pass a problem to a DNS host or colleague, send the exact command, the complete output, the time with its time zone and the network you ran it from. A pasted dig reply answers most follow-up questions at once. Remove internal hostnames and private addresses before posting anything publicly.
Pitfalls
- These tools query DNS only. They ignore the hosts file, so an application may behave differently from what you see. Use
getent hostson Linux orResolve-DnsNameandpingon Windows to see the system's view. -
nslookupmay append your network's search suffix to short names. Add a trailing dot, as inexample.com., to ask for exactly that name. - Windows
nslookupdoesn't handle some newer record types well. - Querying
ANYis unreliable, because many servers deliberately return a minimal reply. Ask for each type you need. - An empty
+shortoutput hides the reason. Run the full command to see the status. - Some networks intercept DNS and answer in place of the server you named. If results from every "different" server look identical and strange, suspect that.
Once you know which layer is wrong, the fix usually becomes obvious: change the record, correct the delegation, flush a cache or wait out a TTL.