[DNS Fundamentals Part 8] Investigating with Commands: How to Read dig, nslookup, Resolve-DnsName, and resolvectl

DNS Fundamentals Part 8 Investigating with Commands: How to Read dig, nslookup, Resolve-DnsName, and resolvectl DNS

“nslookup returns the new IP address, but my browser still connects to the old server.”
“dig gives me SERVFAIL. Where should I start?”

In DNS troubleshooting, what you see changes depending on which command you used, who you asked, and what you asked. If you do not know each command’s quirks, you can look at a correct result and still reach the wrong conclusion.

Through Part 7, we have covered how DNS works and how to operate it. In Part 8, we look at the tools for actually investigating it: how to use dig, nslookup, PowerShell’s Resolve-DnsName, and Linux’s resolvectl, and how to read their output.

The big picture of name resolution (the roles of the stub resolver, caching DNS, and authoritative DNS) is explained in Part 1, “What Is DNS? How Name Resolution Works and Its Three Key Players.”

▶ This part is also available as a YouTube video (about 22 min) (it is also embedded at the end of this article).


The overall layout of dig output

Let’s start with the output of dig www.example.com A (an excerpt). dig comes with BIND and works on Linux and macOS.

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

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;www.example.com.                IN      A

;; ANSWER SECTION:
www.example.com.         245     IN      A       192.0.2.10

;; Query time: 12 msec
;; SERVER: 192.0.2.53#53(192.0.2.53) (UDP)
;; MSG SIZE  rcvd: 60

Lines that start with ; are commentary. Lines without a ; are the records themselves.

  • HEADER: the response code (status), the flags, and the number of records in each section. Look here first
  • OPT PSEUDOSECTION: EDNS information. Extended DNS Errors (EDE) also appear here
  • QUESTION / ANSWER: what was asked and what came back. The second column of the ANSWER is the remaining TTL (in seconds)
  • The last four lines: the time taken, the server that answered and the transport (UDP/TCP), and the size of the response
Diagram showing that one dig ANSWER line has five columns (name, TTL in remaining seconds, class, type, and value), and that the reading order is 1. HEADER (status), 2. ANSWER, 3. the SERVER line

The reading order is 1. HEADER (status) → 2. ANSWER → 3. the SERVER line. Every record type has the same five columns: name, TTL, class, type, and value.


Reading the header and flags

ItemExampleMeaning
statusNOERROR / NXDOMAIN / SERVFAILThe response code (RCODE). Check this first
flags: qrqrIndicates that this is a response
flags: aaaaThe answer comes from the authoritative DNS server itself. It is not set on answers from a cache
flags: rd / rard rard = recursion was requested; ra = this server is willing to do recursion
flags: ad / cdadad = the resolver validated the answer with DNSSEC; cd = the client asked it not to validate
flags: tctcThe response was truncated. Ask again over TCP (Part 4)
CountsANSWER: 1, AUTHORITY: 0The number of records in each section. ANSWER: 0 means “no answer”
The OPT lineudp: 1232, flags: do, COOKIE, EDEThe EDNS buffer size, the DNSSEC request (do), the DNS Cookie, and Extended DNS Errors

Even with status: NOERROR, if ANSWER is 0 there is no answer (NODATA). Also, if you send a query with rd to an authoritative DNS server, you see ;; WARNING: recursion requested but not available. It means the server does not do recursion for you; it is not an error.


Sections, TTL, and query time

  • ANSWER: the answer (including the intermediate records if a CNAME was followed)
  • AUTHORITY: the NS records of the delegated servers, or the SOA when there is no answer
  • ADDITIONAL: the IP addresses of the NS servers (glue) and similar records
Diagram showing that an authoritative DNS server returns the configured TTL of 300 unchanged, while a caching DNS server's TTL counts down over time and is fetched again from the authoritative server once it reaches 0, and that a Query time of 0 to 1 msec means the answer came from cache while tens to hundreds of msec means the authoritative server was asked

The number in the second column of a record is the TTL (the remaining number of seconds the record may be cached).

  • Ask an authoritative DNS server, and you get the configured value itself
  • Ask a caching DNS server, and you get a value that has counted down over time

If the TTL has gone down when you run the query twice, the answer is coming from a cache.

Query time is also a clue. 0 to 1 msec suggests the answer came from a cache, and tens to hundreds of msec suggests the query went all the way to an authoritative DNS server. The SERVER line shows the server that actually answered. If it is 127.0.0.53, Linux’s systemd-resolved answered.


The main dig options

OptionMeaningWhen to use it
@192.0.2.53Specifies the server to queryCompare the internal DNS, an external DNS, and an authoritative DNS directly
MX, AAAA, TXT, etc.Specifies the record type (the default is A)Check for a missing record of a given type
+shortShows only the values of the answerScripts, comparing several servers
+norecDoes not request recursion (no rd)Checking an authoritative DNS, looking inside a cache
+traceFollows the delegations from the root, step by stepFinding mistakes in delegation or glue
-x 192.0.2.10Queries a reverse lookup (PTR)Checking that a reverse record is registered
+tcpQueries over TCPChecking that TCP/53 gets through
+dnssecSets the DO bit and also shows RRSIGChecking whether signatures exist and when they expire
$ dig @198.51.100.53 example.com MX +norec +noall +answer
$ dig @192.0.2.53 www.example.com +dnssec +bufsize=1232 +nsid
PS> Resolve-DnsName example.com -Type MX -NoRecursion -Server 198.51.100.53   # same as the first line

Other options that are often used are +nsid (which anycast site answered), +bufsize=N (the EDNS buffer size, for checking problems where large responses get dropped), +cd (fetch the data with DNSSEC validation turned off), and +noall +answer (show only the answer).


How to read dig +trace

+trace follows the delegations from the root, step by step, and prints the response at each stage.

$ dig +trace www.example.com
.                  81000   IN  NS   a.root-servers.net.
(omitted: the root servers' NS and RRSIG)
;; Received 525 bytes from 192.0.2.53#53(192.0.2.53) in 3 ms

com.               172800  IN  NS   a.gtld-servers.net.
(omitted: the com NS, DS, and RRSIG)
;; Received 834 bytes from 199.7.83.42#53(l.root-servers.net) in 12 ms

example.com.       86400   IN  NS   ns1.example.com.
example.com.       86400   IN  NS   ns2.example.com.
;; Received 120 bytes from 192.5.6.30#53(a.gtld-servers.net) in 8 ms

www.example.com.   300     IN  A    192.0.2.10
;; Received 60 bytes from 192.0.2.53#53(ns1.example.com) in 5 ms
  • In each block, read who was asked (Received … from) and where the query was delegated to. Only the first block gets the list of root servers from your local resolver
  • dig itself does the iterative queries, so it does not go through the caching DNS. If the result differs from a normal query, suspect the cache or the resolver’s settings
  • You can find delegation mistakes such as the trace stopping partway, the parent’s NS and the child’s NS being different, or a stale glue IP address (Part 2)

dig 9.20 also prints the DS and RRSIG lines. Note that on a network where machines cannot reach external DNS (UDP/TCP 53) directly, +trace fails. PowerShell has no equivalent feature; with -NoRecursion, you ask the root, the TLD, and the authoritative servers one after another.


Viewing DNSSEC validation results with delv

delv comes with BIND and is a dig that does the DNSSEC validation itself. It validates the response received from the resolver, starting from the root trust anchor built into the tool (Part 9).

$ delv www.example.com A
; fully validated
www.example.com.   300  IN  A      192.0.2.10
www.example.com.   300  IN  RRSIG  A 13 3 300 20261009000000 20260925000000 12345 example.com. (omitted)

$ delv www.unsigned.example.com A
; unsigned answer
www.unsigned.example.com. 300 IN A 203.0.113.20

$ delv @192.0.2.53 +cd www.bad.example.org A
;; validating bad.example.org/DNSKEY: no valid signature found (DS)
;; no valid RRSIG resolving 'bad.example.org/DNSKEY/IN': 192.0.2.53#53
;; broken trust chain resolving 'www.bad.example.org/A/IN': 192.0.2.53#53
;; resolution failed: broken trust chain
Diagram showing that the first line of delv output is one of three verdicts (fully validated means the signature was verified, unsigned answer means the zone is unsigned and this is not a failure, and broken trust chain means the chain is broken between the parent's DS and the child's DNSKEY), and that for a caching DNS server that returns SERVFAIL when validating, you fetch the data with +cd and have delv validate it

The first line tells you the result.

  • fully validated: validation succeeded
  • unsigned answer: the zone is not signed. It is outside the scope of validation and is not a failure
  • negative response, fully validated: the fact that the name or record does not exist was validated

A validating resolver returns only SERVFAIL on failure, so add +cd to fetch the contents and have delv validate them. To see the validation process in detail, add +vtrace. It is important not to confuse “unsigned” with “validation failed.”


nslookup (one-liner and interactive mode)

This is the familiar nslookup on Windows.

C:\> nslookup www.example.com.
Server:  dns1.corp.example.com
Address:  192.0.2.53

Non-authoritative answer:
Name:    www.example.com
Address:  192.0.2.10

C:\> nslookup -type=mx example.com. 198.51.100.53

C:\> nslookup
> server 198.51.100.53
> set type=aaaa
> set debug
> www.example.com.
> exit
  • The one-liner order is nslookup -type=TYPE NAME SERVER. Put a “.” at the end of the name to prevent extra queries caused by appending search domains
  • In interactive mode, set type= and server stay in effect from then on. If the results look strange, check the current settings with set all
  • set debug shows the HEADER (rcode and the number of answers), TTL, AUTHORITY, and ADDITIONAL
  • “Non-authoritative answer” means the answer came from a caching DNS (no aa). If the server name shows as UnKnown, the server simply has no reverse record

This is the point behind the question at the start. nslookup does not use the OS’s DNS client and does its own querying, so the hosts file and the NRPT (Name Resolution Policy Table) do not apply. In other words, nslookup’s result does not necessarily match what an application does.


Resolve-DnsName and ipconfig (Windows)

So to reproduce what an application does on Windows, use Resolve-DnsName.

PS> Resolve-DnsName www.example.com -Type A -Server 192.0.2.53 -DnsOnly

Name                  Type   TTL   Section    IPAddress
----                  ----   ---   -------    ---------
www.example.com       A      245   Answer     192.0.2.10

PS> Resolve-DnsName example.com -Type MX -NoHostsFile -DnssecOk
PS> ipconfig /displaydns        # Show the DNS client cache
PS> ipconfig /flushdns          # Delete the cache
PS> Get-DnsClientCache ; Clear-DnsClientCache    # PowerShell versions
Diagram showing that applications and Resolve-DnsName go through the DNS Client service, then the hosts file, cache, and NRPT, before reaching the DNS server, while nslookup bypasses the DNS Client and goes straight to the DNS server
  • Resolve-DnsName resolves names by the same path as the OS’s DNS client (including the NRPT). The results come back as objects, so they are easy to handle in scripts
  • Main parameters: -Type, -Server, -DnsOnly (do not use LLMNR or NetBIOS), -NoHostsFile, -CacheOnly, -NoRecursion, -DnssecOk, -TcpOnly
  • ipconfig /displaydns also shows negative cache entries meaning “the name does not exist”
  • /flushdns clears only the OS cache. The browser’s own cache and the caching DNS server’s cache remain

How dig and Resolve-DnsName correspond

ISC dropped Windows support starting with BIND 9.18 (January 2022), and the last Windows-supported branch, 9.16, reached end of support in April 2024. Current Windows has no built-in dig, so use PowerShell’s Resolve-DnsName.

What you want to dodig (Linux, macOS)PowerShell (built into Windows)
Query with a type and a serverdig @192.0.2.53 example.com MXResolve-DnsName example.com -Type MX -Server 192.0.2.53
Ask an authoritative DNS without recursion+norec-NoRecursion
Query over TCP+tcp-TcpOnly
Reverse lookupdig -x 192.0.2.10Resolve-DnsName 192.0.2.10
Get DNSSEC signatures / turn off validation+dnssec / +cd-DnssecOk / -DnssecCd
Query DNS only, excluding hosts and LLMNR(always DNS only)-DnsOnly -NoHostsFile
Extract just the value+short(Resolve-DnsName NAME).IPAddress, etc.
Flags, EDE, +trace, CAA / HTTPS typesCan show or run themCannot (check with dig on Linux or similar)

Being able to query by the same path as the OS (cache and NRPT) is an advantage over dig. Only for checking zone transfers, use nslookup’s ls -d.

How to read Resolve-DnsName results

PS> Resolve-DnsName www.example.com -Type MX -Server 192.0.2.53      # NODATA
Name        Type  TTL   Section    PrimaryServer     NameAdministrator       SerialNumber
example.com SOA   900   Authority  ns1.example.com   hostmaster.example.com  2026092501

PS> Resolve-DnsName nosuch.example.com
Resolve-DnsName : nosuch.example.com : DNS name does not exist.                 # NXDOMAIN

PS> Resolve-DnsName www.bad.example.org
Resolve-DnsName : www.bad.example.org : DNS server failure.   # SERVFAIL
  • The TTL and Section columns correspond to dig’s ANSWER and AUTHORITY. If there is only an SOA in the Authority section, it is NODATA
  • NXDOMAIN, SERVFAIL, and so on are shown as errors. EDE is not shown, so for SERVFAIL, use -DnssecCd and see whether an answer comes back to tell whether it is a DNSSEC problem
  • On Japanese-language Windows these messages appear in Japanese. The kind of error can be told apart by FullyQualifiedErrorId (DNS_ERROR_RCODE_NAME_ERROR and RCODE_SERVER_FAILURE). On Windows Server 2016, SOA and MX results are displayed as a vertical list, one item at a time
  • The result is an object, so you can process it. An example that lists the SOA serial number from every NS (the homework from Part 7):
PS> Resolve-DnsName example.com -Type NS | Where-Object Type -eq NS | ForEach-Object {
      $ns = $_.NameHost
      Resolve-DnsName example.com -Type SOA -Server $ns | Where-Object Type -eq SOA |
        Select-Object @{n='NS';e={$ns}}, SerialNumber }

Checking in an Active Directory environment

When you cannot sign in to the domain or cannot join a domain, check in the following order whether the PC can find the domain controller (DC) through DNS. The example domain name is corp.example.com.

1. Can you query the DC’s SRV record?

PS> Resolve-DnsName -Type SRV _ldap._tcp.dc._msdcs.corp.example.com

Check that the DC’s host name and port 389 (LDAP) come back. If they do not, either the DNS server the PC is using is not the internal DNS (a DC), or the SRV record is not registered. You can check which DNS server the PC is using under “DNS Servers” in ipconfig /all.

2. Can the PC find a DC?

PS> nltest /dsgetdc:corp.example.com

This shows the name and address of the DC actually found through the mechanism the PC uses to look for DCs (the DC Locator). If it fails, first check the SRV record in step 1.

3. The health of DNS on the DC

PS> dcdiag /test:dns

The DNS tests run only when you specify /test:dns (they are not included in a plain dcdiag with no arguments). Run it as an administrator on a DC, or on a PC with the AD DS management tools installed, and work through the failed items in order. Microsoft’s procedure says to run it as a member of Enterprise Admins (or with equivalent permissions).

4. Register the records again

PS> ipconfig /registerdns        # Re-register this PC's host records (A, etc.)
PS> Restart-Service Netlogon     # On a DC: re-register the DC's SRV records

Use these when you suspect records were not registered. A DC’s Netlogon service registers its SRV records when the DC starts, when Netlogon restarts, and every hour after that. You can check the list of records it is supposed to register in %SystemRoot%\System32\Config\netlogon.dns on the DC.

The mechanics of AD-integrated DNS (SRV records, the _msdcs zone, and dynamic updates) are explained in Part 10, “DNS in the cloud and on corporate networks.”


resolvectl (Linux’s systemd-resolved)

On Linux that uses systemd-resolved (Ubuntu and others), investigate with resolvectl.

$ resolvectl query www.example.com
www.example.com: 192.0.2.10                   -- link: eth0

-- Information acquired via protocol DNS in 1.8ms.
-- Data is authenticated: no; Data was acquired via local or encrypted transport: no
-- Data from: cache

$ resolvectl status eth0       # Per-link DNS servers, DNS Domain, DoT, and DNSSEC settings
$ resolvectl statistics        # Cache hit counts and DNSSEC verdict counts
$ resolvectl flush-caches      # Delete the cache
Diagram showing that applications and dig (without @) ask systemd-resolved at 127.0.0.53, which goes through the cache and per-link routing, so that eth0 goes to the internal DNS while the VPN's tun0 sends only ~corp.example.com to the internal-side DNS, along with the role of each resolvectl subcommand
  • nameserver 127.0.0.53 in /etc/resolv.conf points to this service. If you run dig without @, systemd-resolved answers first (Part 3)
  • resolvectl query resolves by the same path as applications and shows whether the answer came from cache (Data from) and whether it was validated with DNSSEC (authenticated). Specify the type like -t MX
  • resolvectl status shows, for each link (NIC), which DNS server is used and which domains are routed to which link (DNS Domain; entries with ~ are for routing only). Use it to investigate “only internal names fail to resolve” while on a VPN
  • statistics is handy for checking the number of cache hits and misses and timeouts

How each response type looks

As a summary of what we have covered so far, here is how each response type looks.

Flowchart for telling response types apart: first check whether a response came back, then what the status is, and for NOERROR how many ANSWER records there are, to distinguish normal, NODATA, NXDOMAIN, SERVFAIL, REFUSED, FORMERR, and timeout
TypeWhat dig showsWhat nslookup showsMain causes and what to check next
NOERRORstatus: NOERROR, ANSWER: 1 or moreThe name and Address are shownNormal. Always read the rcode and the ANSWER count together
NODATAstatus: NOERROR, ANSWER: 0, SOA in AUTHORITYNo error; SOA information is shownThe name exists but that type does not. A missing AAAA, MX, or similar record
NXDOMAINstatus: NXDOMAIN, SOA in AUTHORITYNon-existent domainThe name does not exist. A typo, an unregistered name, or the wrong server being queried
SERVFAILstatus: SERVFAIL, sometimes with EDEServer failedCannot reach the authoritative DNS, or DNSSEC validation failed. Isolate with +cd and EDE
REFUSEDstatus: REFUSED, EDE: 20, etc.Query refusedDenied by an ACL, or an authoritative DNS was asked about a name it is not responsible for
FORMERRstatus: FORMERR, a WARNING about EDNSFormat errorThe other side or a device on the path cannot interpret EDNS
No responsecommunications error … timed outDNS request timed outDropped by a firewall, or the server is down. Not the same as REFUSED

Here is what it looks like in actual output.

(NODATA: the MX of www.example.com)
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40148
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
example.com.  900  IN  SOA  ns1.example.com. hostmaster.example.com. 2026092501 3600 900 1209600 900

(SERVFAIL: DNSSEC validation failure)
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 9270
; EDE: 9 (DNSKEY Missing): (no SEP matching the DS found for bad.example.org.)

(REFUSED: an authoritative DNS was asked recursively about a name it is not responsible for)
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 47847
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
; EDE: 20 (Not Authoritative)
  • With NODATA and NXDOMAIN, an SOA is attached in AUTHORITY. The TTL of this SOA is how long the “does not exist” result is cached (negative caching, Part 3)
  • EDE 9 on a SERVFAIL means “the child zone has no key that matches the parent’s DS“. A typical cause is forgetting to replace the DS when keys are rolled over (Part 9)
  • REFUSED has no ra and shows a WARNING because the query went to an authoritative DNS server that does not do recursion. Check the role of the server you asked
  • With FORMERR, dig prints ;; WARNING: EDNS query returned status FORMERR - retry with '+noedns'

Seeing DNS in a packet capture

When the commands do not tell you enough, look at the packets.

# tcpdump -nni eth0 port 53
IP 192.0.2.100.51234 > 192.0.2.53.53: 4660+ [1au] A? www.example.com. (44)
IP 192.0.2.53.53 > 192.0.2.100.51234: 4660 1/0/1 A 192.0.2.10 (60)
IP 192.0.2.100.40001 > 192.0.2.53.53: 1235+ [1au] AAAA? nosuch.example.com. (47)
IP 192.0.2.53.53 > 192.0.2.100.40001: 1235 NXDomain 0/1/1 (98)

In tcpdump, 4660+ is the ID and rd, [1au] is the EDNS OPT, and 1/0/1 is the number of answer, authority, and additional records. If a query is not paired with a response, it was dropped somewhere along the way.

What you want to seeWireshark display filter
DNS onlydns
A specific namedns.qry.name == “www.example.com”
Error responses (NXDOMAIN is 3)dns.flags.rcode != 0
Slow responses (seconds)dns.time > 0.5
Truncated responsesdns.flags.truncated == 1
Encrypted DNS (DoT, DoQ)tcp.port == 853 or udp.port == 853
Diagram showing that capturing with tcpdump at two points, between the client and the caching DNS and between the caching DNS and the authoritative DNS, tells you where to investigate depending on which segment the responses stop in: the caching DNS side, the authoritative DNS or network path side, or the application side

The trick is to capture at two points and find the segment where the responses stop.

  • At 1 (client ⇔ caching DNS), queries but no responses → the caching DNS side
  • At 2 (caching DNS ⇔ authoritative DNS), no response from the authoritative DNS → the authoritative DNS or the network path (firewall) side
  • At both 1 and 2, queries and responses are paired → the application side

Note that DoH blends into HTTPS on port 443, so you cannot see its contents. Capture packets in accordance with your organization’s rules.


Think about it

  1. You run dig against the internal caching DNS and get SERVFAIL, but with +cd (-DnssecCd in PowerShell) you get NOERROR with an answer. What is happening, and what do you check next?
  2. nslookup returns the new IP address, but the browser still connects to the old server. Which cache do you suspect, and how do you check?
  3. dig +trace shows the new record, but plain dig returns the old value. What does this difference mean?

Hint: The sections of this article “Sections, TTL, and query time,” “Viewing DNSSEC validation results with delv,” “Resolve-DnsName and ipconfig (the scope of the cache),” and “How each response type looks” each lead to an answer.


Summary

  • Read dig in the order HEADER (status) → ANSWER → SERVER
  • If the TTL is counting down, it is a cache answer; if aa is set, it is an authoritative answer
  • +trace does not go through the caching DNS. Compare it with the normal result and look at the difference
  • The first line of delv tells you “unsigned” from “validation failed“
  • nslookup does not go through the hosts file or the NRPT. To reproduce an application, use Resolve-DnsName or resolvectl query
  • Read a response type from the rcode and the ANSWER count together. Capture at two points

Next time, we cover attacks on DNS and how to defend against them, including DNSSEC, which can be the cause of the SERVFAIL we saw here.


Watch the video

This part is also explained in a YouTube video (about 22 min).

All parts of the series are in the DNS Fundamentals playlist on YouTube.

The DNS Fundamentals series (12 parts)

All 12 parts with a reading guide: DNS Fundamentals

  1. What Is DNS? How Name Resolution Works and Its Three Key Players
  2. The domain name hierarchy and delegation
  3. How name resolution works
  4. DNS messages and transport
  5. Resource records, part 1
  6. Resource records, part 2
  7. Running authoritative DNS servers
  8. Investigating with commands (this article)
  9. DNS security
  10. DNS in the cloud and on corporate networks
  11. DNS troubleshooting
  12. DNS design exercises

This series is the English edition of 【DNS入門】, originally written in Japanese.

コメント

Copied title and URL