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".

Command examples
Windows : Address lookups
nslookup example.com
Resolve-DnsName example.com
        
macOS : Address lookups
dig example.com
dig example.com +short
dig AAAA example.com +short
        
Linux : Address lookups
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.

Command examples
Windows : Record types with nslookup
nslookup -type=mx example.com
nslookup -type=txt example.com
nslookup -type=ns example.com
nslookup -type=txt _dmarc.example.com
        
macOS : Record types with dig
dig MX example.com +short
dig TXT example.com +short
dig NS example.com +short
dig TXT _dmarc.example.com +short
        
Linux : Record types with dig
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.

Command examples
Windows : Choose the server

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
        
macOS : Choose the server

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
        
Linux : Choose the server

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.

Command examples
macOS : Trace, reverse, and TTL
dig +trace example.com
dig -x 8.8.8.8 +short
dig example.com | grep -A2 "ANSWER SECTION"
        
Linux : Trace, reverse, and TTL
dig +trace example.com
dig -x 8.8.8.8 +short
dig example.com | grep -A2 "ANSWER SECTION"
        
Windows : Reverse lookup and detail
nslookup 8.8.8.8
nslookup -debug example.com
        

Related Articles

Useful tools