Skip to content
Visual explainer 1h 30m to learn 4 steps

dig, nslookup & resolver checks

Diagnose DNS problems by querying specific servers and record types.

By Invicly Tech, , in Computer Networking. About 10 minutes to read.

Topic 36 of 51

In short

dig and nslookup query DNS directly so you can see exactly what a server answers. Querying specific servers separates a broken local resolver from a broken authoritative zone. Following the delegation with +trace reveals misconfigured name servers.

Explained simply

DNS turns names like example.com into IP addresses. When a website "cannot be found", DNS is often the reason. The tools dig and nslookup let you ask DNS servers questions directly and see their exact answers, instead of guessing from a browser error.

There are two kinds of DNS servers to keep apart. A resolver is the helper your computer asks; it does the searching and remembers (caches) answers. An authoritative server is the official source for one domain. A problem can sit in either one, and dig lets you ask each of them separately.

Every answer comes with a status. NOERROR means the question was answered. NXDOMAIN means the name does not exist. SERVFAIL means the resolver tried but could not get a good answer. Reading this status is the first step of every DNS check.

Your own computer also has a DNS setup: which resolvers it uses, a local file of names (/etc/hosts), and sometimes its own small cache. Many "DNS problems" are really a wrong setting on the client, so checking it is part of the job.

Press Play on a diagram to walk through it one step at a time.

FlowDiagnosing 'site not found'
  1. 1
    Local resolver

    dig example.com

  2. 2
    Public resolver

    dig @1.1.1.1 example.com

  3. 3
    Authoritative

    dig @ns1.example.com example.com

  4. 4
    Delegation

    dig +trace example.com

  5. 5
    Client config

    resolvectl status or /etc/resolv.conf

MapWhat the response code tells you
dig status
  • NOERROR with answer
    • Name resolves
    • Check the data is the right IP
  • NOERROR, no answer
    • Name exists, not this type
    • Called NODATA, e.g. no AAAA
  • NXDOMAIN
    • Name does not exist
    • Typo, or record never created
  • SERVFAIL
    • Resolver could not get a valid answer
    • Broken delegation or DNSSEC
  • REFUSED
    • Server will not answer you
    • Not authoritative, or recursion denied

In depth

Reading dig output

dig prints a header, then sections. The header line shows status (NOERROR, NXDOMAIN, SERVFAIL, REFUSED) and flags. qr means this is a response, rd means recursion was asked for, ra means the server offers recursion, aa means the answer is authoritative (it came from the zone owner, not a cache), and ad means DNSSEC validation succeeded.

The ANSWER section holds records in the form name, TTL, class, type, data. The TTL is in seconds; from a resolver it counts down as the cached copy ages, so asking twice shows a smaller number. The AUTHORITY section lists name servers or, for a missing name, the SOA record. At the bottom, SERVER shows who actually answered and Query time shows how long it took, a quick check on a slow resolver.

  • +short prints only the data
  • +noall +answer prints only the answer section
  • -x 8.8.8.8 does a reverse (PTR) lookup
  • +tcp forces TCP, useful for large answers

Asking the right server

By default dig asks the resolver from your system configuration. Adding @server sends the question elsewhere, which is how you isolate the fault. If dig example.com fails but dig @1.1.1.1 example.com works, your local resolver is the problem. If both fail, look at the domain itself.

To see the source of truth, find the zone's name servers with dig NS example.com +short, then ask one of them directly with dig @ns1.example.com example.com. Add +norecurse so the server answers only from its own data. If the authoritative answer is right but resolvers show the old value, you are seeing caching: they will update when the old record's TTL runs out. Lowering the TTL a day before a planned change makes switches faster.

FlowWhere does the wrong answer come from?
  1. 1
    Client lookup

    getent hosts name uses /etc/hosts and the resolver

  2. 2
    Local resolver

    dig name: what the system resolver says

  3. 3
    Public resolver

    dig @1.1.1.1 name: an independent cache

  4. 4
    Authoritative

    dig @ns1 name +norecurse: the truth

  5. 5
    Conclusion

    First place the answer goes wrong is the fault

Following the delegation with +trace

dig +trace ignores your resolver and walks the tree itself: it asks a root server, which refers it to the servers for .com, which refer it to the domain's name servers, which give the final answer. You see every referral, so a broken step stands out.

Common findings: the parent zone (the registrar's NS records) points to name servers that no longer host the zone, called lame delegation; one of several name servers has an old copy of the zone (compare the SOA serial with dig @each-server example.com SOA +short); or DNSSEC records at the parent do not match the zone's keys, which makes validating resolvers return SERVFAIL. For DNSSEC, dig +dnssec shows signatures, and comparing with dig +cd (checking disabled) tells you if validation is the cause.

SequenceWhat dig +trace walks through
dig
Root server
.com servers
example.com NS
  1. 1Who handles example.com?
    dig to Root server: Who handles example.com?
  2. 2Ask the .com servers (referral)
    Root server to dig: Ask the .com servers (referral)
  3. 3Who handles example.com?
    dig to .com servers: Who handles example.com?
  4. 4Ask ns1.example.com (referral)
    .com servers to dig: Ask ns1.example.com (referral)
  5. 5A record for example.com?
    dig to example.com NS: A record for example.com?
  6. 6Answer with aa flag set
    example.com NS to dig: Answer with aa flag set

Checking the client's resolver setup

On most modern Linux systems, systemd-resolved runs a local stub resolver at 127.0.0.53, and /etc/resolv.conf just points to it. So reading resolv.conf shows nameserver 127.0.0.53, not your real DNS servers. Use resolvectl status to see the real upstream servers per interface, resolvectl query name to test through it, and resolvectl flush-caches to clear its cache.

Remember that dig and nslookup talk DNS directly and skip /etc/hosts. Normal programs use the system library, which follows /etc/nsswitch.conf (usually files first, then dns). So a stale line in /etc/hosts can break a browser while dig looks perfect. getent hosts name tests the same path real programs use. On Windows, ipconfig /all shows DNS servers and ipconfig /flushdns clears the cache; on macOS, scutil --dns shows the resolver setup.

  • resolvectl status: real DNS servers per link
  • getent hosts name: lookup as applications do it
  • DNS uses UDP and TCP port 53; DoT uses TCP 853; DoH uses 443

Learn it in 4 short steps

About 25m each. Track them with a timer in your plan.

  1. 1
    Query records with dig~25m
  2. 2
    Query a specific server with @~25m
  3. 3
    Follow delegation with +trace~25m
  4. 4
    Check the local resolver configuration~25m

Key points

  • Check status in the header: NOERROR, NXDOMAIN or SERVFAIL.
  • The aa flag marks an authoritative answer.
  • Different answers from different resolvers suggest caching or propagation delay.
  • SERVFAIL often means a DNSSEC or delegation problem.

Key terms

Tap a card to flip it. 0/4 known

Examples

bash
dig example.com +noall +answer +comments | head
dig @8.8.8.8 example.com A +short
dig example.com NS +short
dig +trace example.com
resolvectl status | grep -A2 'DNS Servers'

A new record works for you but not for your colleague

You changed app.example.com from 203.0.113.10 to 203.0.113.50. Step 1: ask the authoritative server; it returns .50 with the aa flag, so the zone is correct. Step 2: ask your colleague's resolver; it returns .10 with a TTL of 2900 seconds. Step 3: that is the old answer still cached, and it will expire in about 48 minutes. Step 4: either wait, flush that resolver if you control it, or next time lower the TTL to 300 a day before the change.

bash
dig NS example.com +short
dig @ns1.example.com app.example.com A +norecurse +noall +answer
# app.example.com. 3600 IN A 203.0.113.50
dig @10.0.0.53 app.example.com A +noall +answer
# app.example.com. 2900 IN A 203.0.113.10   (cached old value)

Browser fails, dig works

On a developer laptop, the browser cannot open api.internal, yet dig api.internal returns the right IP. Step 1: test the way applications resolve with getent hosts api.internal; it returns 127.0.0.1. Step 2: grep /etc/hosts and find an old line from a local test. Step 3: remove the line and run getent again. The lesson: dig skips /etc/hosts, so always confirm with getent hosts.

bash
dig +short api.internal        # 10.20.40.25 (correct)
getent hosts api.internal      # 127.0.0.1 api.internal (wrong)
grep api.internal /etc/hosts   # stale test entry
sudo sed -i '/api.internal/d' /etc/hosts
getent hosts api.internal      # 10.20.40.25

Quick reference

  • dig name A +short: just the IPv4 addresses
  • dig @1.1.1.1 name: ask a specific resolver to bypass your local one
  • dig name MX, TXT, NS, SOA, AAAA, CNAME: ask for a specific record type
  • dig -x 192.0.2.1: reverse lookup (PTR record)
  • dig +trace name: follow referrals from the root down
  • nslookup name 8.8.8.8: quick query of a given server (works on Windows too)
  • resolvectl status shows real upstream servers; resolv.conf may only show 127.0.0.53
  • getent hosts name resolves like applications do, including /etc/hosts

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1What does the aa flag in a dig response mean?

Question 2

2dig example.com fails with SERVFAIL, but dig +cd example.com works. What is the likely cause?

Question 3

3/etc/resolv.conf shows only nameserver 127.0.0.53. What does that mean?

Question 4

4A colleague still gets the old IP an hour after you changed a record. What most likely explains it?

Question 5

5Why can dig return the right IP while the browser uses the wrong one?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Look up the A, AAAA, MX and NS records for a domain you use, printing only the data.

  2. Exercise 2medium

    Check that all of a domain's name servers serve the same zone version by comparing their SOA serial numbers.

  3. Exercise 3hard

    Write a small script that, for one name, prints the answer from the system lookup, the local resolver, a public resolver and the authoritative server, so a mismatch is obvious.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Should I use dig or nslookup?
dig gives clearer, more complete output and is the usual choice on Linux and macOS. nslookup is installed on Windows by default and is fine for quick checks.
How do I flush my DNS cache?
On Linux with systemd-resolved, run resolvectl flush-caches. On Windows, run ipconfig /flushdns. On macOS, run sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder.
Why does DNS propagation take so long?
Nothing is really pushed out. Each resolver keeps its cached copy until the record's TTL expires, so a 24-hour TTL can mean up to a day of old answers.
Does DNS use UDP or TCP?
Both on port 53. Most queries use UDP; TCP is used for large answers, zone transfers and as a fallback when a UDP reply is truncated.

Go deeper

ShareXLinkedInWhatsApp