nslookup and dig: A Practical Guide With Real Examples
Use nslookup and dig to query any DNS record, test a specific resolver, trace a lookup from the root, and read NXDOMAIN, SERVFAIL, and empty answers correctly.
Published by SpeedTesting.dev · Updated · 3 min read
Quick answer
nslookup is available everywhere and fine for quick checks; dig gives cleaner, more complete output. Querying the same name against two resolvers is the fastest way to tell a local DNS fault from a domain problem.
nslookup or dig?
Both tools send DNS queries and show the answers. nslookup ships with Windows, macOS, and most Linux systems, so it is the safe choice when you are on an unfamiliar machine. dig is standard on macOS and most Linux distributions and is preferred by administrators because its output shows the full response: status code, flags, TTLs, and which server answered.
On Windows, PowerShell's Resolve-DnsName is a capable alternative to dig. If you would rather not use a terminal at all, our DNS lookup tool runs the same kinds of queries from our server.
Basic Queries
The simplest query asks your default resolver for a name's address. nslookup prints the resolver it used first, then the answer. The words "Non-authoritative answer" simply mean the reply came from a resolver's cache rather than directly from the domain's own nameserver; it is normal and not an error.
With dig, adding +short strips the output to just the answer, which is handy in scripts. Without it, look for the "status:" field in the header and the "ANSWER SECTION".
nslookup example.com
Resolve-DnsName example.com
dig example.com
dig example.com +short
dig AAAA example.com +short
dig example.com
dig example.com +short
dig AAAA example.com +short
Querying Specific Record Types
Most DNS questions are about something other than the A record. Add the record type to ask for it directly:
- MX to see which servers receive a domain's email.
- TXT to read SPF policies and verification records.
- NS to see which nameservers are authoritative.
- CNAME to check whether a name is an alias.
- The _dmarc subdomain's TXT record to read a DMARC policy.
If a TXT query returns several records, read each one; domains often publish many verification strings alongside a single SPF record.
nslookup -type=mx example.com
nslookup -type=txt example.com
nslookup -type=ns example.com
nslookup -type=txt _dmarc.example.com
dig MX example.com +short
dig TXT example.com +short
dig NS example.com +short
dig TXT _dmarc.example.com +short
dig MX example.com +short
dig TXT example.com +short
dig NS example.com +short
dig TXT _dmarc.example.com +short
Asking a Specific Resolver or Nameserver
This is the single most useful technique for troubleshooting. Querying the same name against different servers tells you where an answer goes wrong:
- Ask your normal resolver, then a public resolver such as 1.1.1.1. Different answers mean one of them has a stale cache or is filtering the domain.
- Ask the domain's authoritative nameserver directly (find it with an NS query). This shows what the domain owner has actually published, with no caching involved. If the authoritative answer is correct but resolvers disagree, you are waiting for caches to expire.
With nslookup, put the server after the name. With dig, use the @ prefix.
Replace ns1.your-dns-host.example with a nameserver returned by the NS query.
nslookup example.com 1.1.1.1
nslookup -type=ns example.com
nslookup example.com ns1.your-dns-host.example
Replace ns1.your-dns-host.example with a nameserver returned by the NS query.
dig @1.1.1.1 example.com
dig NS example.com +short
dig @ns1.your-dns-host.example example.com
Replace ns1.your-dns-host.example with a nameserver returned by the NS query.
dig @1.1.1.1 example.com
dig NS example.com +short
dig @ns1.your-dns-host.example example.com
Reading the Result: NOERROR, NXDOMAIN, SERVFAIL, and Empty Answers
- NOERROR with an answer: the record exists and here it is.
- NOERROR with no answer (sometimes called NODATA): the name exists, but not with the record type you asked for. For example, a domain might have an A record but no AAAA record. nslookup may say "No answer" in this case.
- NXDOMAIN: the name does not exist at all. Check spelling, and check that the domain has not expired. nslookup reports this as "Non-existent domain".
- SERVFAIL: the resolver could not get a valid answer. Common causes are broken DNSSEC signatures, unreachable or misconfigured authoritative servers, or a delegation pointing to nameservers that do not answer for the domain. Try the authoritative server directly and check the domain with our DNSSEC checker.
- REFUSED: the server you asked will not answer that query, typically because you asked an authoritative server about a domain it does not host.
Three Advanced Tricks Worth Knowing
Trace a lookup from the root
dig +trace performs the full resolution chain itself, starting at the root servers, and prints each delegation step. It shows exactly where a broken delegation or a wrong nameserver appears.
Reverse lookups
dig -x takes an IP address and returns its PTR record. Mail servers commonly check that a sending IP has a sensible reverse name, and our reverse DNS tool does the same check from the web.
Check TTLs during a migration
In full dig output, the number before the record type is the remaining TTL in seconds. Query your resolver twice a few seconds apart and you will see it count down, which tells you how long the cached value will survive.
dig +trace example.com
dig -x 8.8.8.8 +short
dig example.com | grep -A2 "ANSWER SECTION"
dig +trace example.com
dig -x 8.8.8.8 +short
dig example.com | grep -A2 "ANSWER SECTION"
nslookup 8.8.8.8
nslookup -debug example.com
Related Articles
How to Read a Traceroute (and What It Can’t Tell You)
Run traceroute on Windows, macOS, or Linux and interpret the output correctly: hop latency, asterisks, rate limiting, and how to spot where a real problem begins.
SPF, DKIM, and DMARC: A Practical Setup and Troubleshooting Guide
Set up email authentication for your domain in the right order, avoid the SPF lookup limit and other common mistakes, and move DMARC from monitoring to enforcement safely.
How DNS Works and How to Fix Common DNS Problems
Follow a DNS lookup from your browser to the authoritative server, learn the record types you will actually meet, and fix slow or failing name resolution step by step.
Ping, Latency, Jitter, and Packet Loss: What the Numbers Mean
A practical guide to the four connection-quality numbers that matter for calls and games, with healthy ranges, common causes of bad results, and commands to measure them yourself.