Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Networking

nslookup and dig: DNS lookup commands for Windows and Linux

Use nslookup, dig and Resolve-DnsName to query A, MX, TXT and NS records, ask a chosen server, read authoritative answers, and see why apps may disagree.

CloudSat teamNovember 18, 20266 min read
Abstract illustration of a question mark traveling down a branching tree of servers and returning as a glowing address
On this pageWhich tool, where

Three tools answer almost every DNS question an admin has: nslookup, built into Windows and available on Linux; dig, the standard on Linux and macOS; and Resolve-DnsName in PowerShell. They ask DNS servers directly, which makes them precise, and it is also why their answer sometimes differs from what a browser sees. This guide covers the queries you will run most, how to read the output, and a short routine for tracking down a wrong answer.

Which tool, where

Tool Available on Best at
nslookup Windows; Linux with the BIND utilities Quick lookups on any Windows machine
dig Linux, macOS; Windows through WSL Full detail: flags, TTLs, tracing delegations
Resolve-DnsName Windows PowerShell and PowerShell 7 on Windows Scripts, and seeing what Windows itself resolves

On Debian and Ubuntu, sudo apt install bind9-dnsutils installs both dig and nslookup. On the RHEL family the package is bind-utils.

nslookup: the everyday queries

nslookup example.com
nslookup -type=AAAA example.com
nslookup -type=MX example.com
nslookup -type=TXT example.com
nslookup -type=NS example.com
nslookup example.com 1.1.1.1
nslookup 203.0.113.10

The first two lines of every answer name the server that replied. "Non-authoritative answer" means that server is a resolver answering from its cache or from a lookup it made for you, not the zone's own nameserver. That is normal. Adding a server address at the end, as in the sixth line, asks that server instead of your configured one, and an IP address on its own triggers a reverse (PTR) lookup.

For several questions in a row, use interactive mode:

nslookup
> set type=MX
> server 9.9.9.9
> example.com
> set debug
> example.com
> exit

set debug prints the full response, including TTLs and the authority section.

One Windows quirk catches people: nslookup may append your network's DNS suffix and look up example.com.corp.example before the name you typed. End the name with a dot, nslookup example.com., to mark it as complete.

dig: the same questions with more detail

dig example.com
dig +short example.com AAAA
dig +short example.com MX
dig @1.1.1.1 example.com TXT
dig -x 203.0.113.10 +short
dig example.com SOA +noall +answer
dig +trace www.example.com

A full dig answer has a header worth reading:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4127
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; ANSWER SECTION:
example.com.            2879    IN      A       203.0.113.10

status is the result code. In the flags, aa appears only when an authoritative server answered, while rd ra mean recursion was requested and available. The number before IN is the remaining TTL: query a resolver twice and you will see it count down, which tells you the answer is cached and when the cache expires.

To see what a zone's own nameserver publishes, skipping every cache, ask it directly without recursion:

dig +short NS example.com
dig @ns1.dnshost.example www.example.com A +norecurse

+trace starts at the root servers and follows each delegation down to the answer, which shows exactly where a broken chain stops.

Resolve-DnsName in PowerShell

Resolve-DnsName example.com
Resolve-DnsName example.com -Type MX
Resolve-DnsName example.com -Type TXT -Server 1.1.1.1
Resolve-DnsName 203.0.113.10
Resolve-DnsName example.com -DnsOnly -NoHostsFile

The output is a set of objects, so it filters and sorts like any PowerShell data: Resolve-DnsName example.com -Type A | Select-Object Name, TTL, IPAddress. Without extra switches it goes through the Windows DNS client, so it sees the hosts file and the local cache the way applications do. -DnsOnly and -NoHostsFile turn that off, which makes it behave like nslookup.

Records admins check most

Beyond addresses, most lookups are about mail and verification. These names follow fixed patterns, so they are easy to query once you know them:

dig +short TXT example.com                          # SPF and site verification strings
dig +short TXT _dmarc.example.com                   # DMARC policy
dig +short TXT selector1._domainkey.example.com     # a DKIM key; the selector comes from your mail provider
dig +short CAA example.com                          # which authorities may issue certificates
dig +short SRV _minecraft._tcp.example.com          # service records, here for a game server

With nslookup the same questions are nslookup -type=TXT _dmarc.example.com and so on. A TXT record that a provider asks you to add for verification is visible once the authoritative server returns it, even if your own resolver still shows the old, empty answer.

Why the tools and your browser disagree

nslookup and dig talk to a DNS server themselves. Applications ask the operating system, which also consults the hosts file, its own cache, and sometimes a VPN's private DNS. Browsers may skip all of that and use DNS over HTTPS with their own provider.

Question Windows Linux
What does the DNS server say? nslookup name dig name
What do applications get? Resolve-DnsName name getent hosts name
Which servers am I using? Get-DnsClientServerAddress resolvectl status

On Linux with systemd-resolved, /etc/resolv.conf usually points at the local stub 127.0.0.53, and resolvectl status shows the real upstream servers per interface. resolvectl query name resolves a name the same way applications do.

Reading the result codes

Result nslookup shows Meaning
NOERROR with an answer The addresses The name and the record type exist
NOERROR, empty answer "No answer", or the name with no address The name exists, but not with that record type
NXDOMAIN "Non-existent domain" or "can't find" The name does not exist in DNS
SERVFAIL "Server failed" The resolver could not get a valid answer, often a DNSSEC or nameserver problem
REFUSED "Query refused" That server will not answer you, usually because it is not an open resolver

The empty NOERROR case surprises people most: a missing AAAA record looks like an error in some tools but simply means the name has no IPv6 address. A name that returns NXDOMAIN has its own guide: NXDOMAIN causes and fixes.

A five-step routine for a wrong answer

  1. Ask your configured resolver: dig example.com or nslookup example.com.
  2. Ask a public resolver: dig @1.1.1.1 example.com. A different answer points at your own resolver or its cache.
  3. Ask the authoritative server: dig @<ns> example.com +norecurse. This is the truth as published.
  4. Trace the delegation: dig +trace example.com, to catch a wrong or stale nameserver.
  5. Ask the operating system: Resolve-DnsName or getent hosts. A difference here means the hosts file, a VPN or a local cache, and flushing the DNS cache is the next step.

Reverse lookups follow the same routine. After setting the PTR record of a CloudSat server in the console (Set reverse DNS for your IPv4), dig -x with the server's address shows when the new name is live.

FAQ

What does "Non-authoritative answer" mean?

The server that replied is a resolver, not the nameserver that owns the zone. It looked the answer up or had it cached. To get an authoritative answer, query one of the domain's NS servers directly.

Why does the TTL change every time I run dig?

A resolver returns the time its cached copy has left, so the number counts down between queries and jumps back up after the cache refreshes. The zone's authoritative server always returns the full TTL you configured, which is a quick way to tell the two kinds of answer apart.

How do I find which DNS server my computer uses?

On Windows, Get-DnsClientServerAddress or ipconfig /all. On Linux, resolvectl status on systems with systemd-resolved, otherwise the nameserver lines in /etc/resolv.conf.

Can these tools test DNS over HTTPS or TLS?

Recent dig releases can: dig @1.1.1.1 +https example.com uses DNS over HTTPS and +tls uses DNS over TLS. nslookup and Resolve-DnsName only speak classic DNS.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.