Sub topic 12
Querying and debugging with dig
This chapter assumes you know what a resolver, an authoritative server, a resource record and a TTL are. It also assumes you can run commands in a terminal. dig is the standard tool for asking DNS questions directly and reading the raw answers.
Basic queries
The general form is dig [@server] name [type]. If you leave out the type, dig asks for an A record. If you leave out the server, it uses the resolver from your system configuration.
dig example.com A
dig +short example.com AAAA
dig +noall +answer example.com MXThe first command prints the full output. +short prints only the record data. +noall +answer turns off every section and then turns the answer section back on, so you see complete record lines without the extra text.
Reading the full output
A full dig response has these parts:
- The header line shows the status and the flags.
- The question section repeats what you asked.
- The answer section holds the records that answer it.
- The authority section lists name servers, or the SOA record for an empty answer.
- The additional section holds extra records, such as the addresses of listed name servers.
The status in the header is the first thing to check:
| Status | Meaning |
|---|---|
| NOERROR | The query worked. An empty answer section means the name exists but has no record of that type. |
| NXDOMAIN | The name does not exist. |
| SERVFAIL | The server could not get an answer. Common causes are an unreachable authoritative server or a DNSSEC validation failure. |
| REFUSED | The server declined to answer you, often because of an access policy. |
The flags tell you who answered and how:
qrmarks a response.rdmeans you asked for recursion.rameans the server offers recursion.aameans the answer came from an authoritative server. A resolver answering from its cache does not set it.
In an answer line such as example.com. 287 IN A 192.0.2.10, the number is the remaining TTL in seconds.
Comparing resolvers
Use @server to pick which resolver you ask. Then repeat the query against your default resolver.
dig @8.8.8.8 example.com A
dig +noall +answer example.com AIf the two answers differ, the resolvers hold different cached data. Run the same query twice against one resolver. A TTL that counts down shows the answer is coming from cache. A TTL that resets to the full value shows the cache has just refreshed.
Walking the delegation chain
dig +trace makes dig do the resolver's job itself. It starts at the root servers and follows each referral down to the authoritative servers.
dig +trace example.comRead the output from top to bottom. Each block shows one referral: the root points to the TLD servers, and the TLD servers point to the domain's name servers. A broken delegation shows up here. Typical signs are a missing NS record, a name server that times out, or a name server that answers without the aa flag.
Reverse lookups
The -x option builds the PTR query for you.
dig -x 192.0.2.10 +noall +answerdig reverses the octets and queries the name under in-addr.arpa. No answer does not mean something is broken. Many addresses have no PTR record.
A debugging routine
- Run
dig nameand check the status. NXDOMAIN and SERVFAIL point in different directions. - Check the TTL and the
aaflag to see whether you got a cached answer. - Query a second resolver and compare.
- Run
+traceto test the delegation. - Query an authoritative server directly with
dig @ns1.example.com example.com A. This shows the true current data, free of caches.
Exercise
You run dig www.example.org and get status NOERROR with an empty answer section, and the authority section holds an SOA record. What does that mean, and how does it differ from NXDOMAIN?
Show answer
The name www.example.org exists, but it has no record of the type you asked for (A by default). NXDOMAIN would mean the name does not exist at all. The SOA record in the authority section is what resolvers use to cache this negative result. Try another type, such as AAAA, to see whether the name has other records.