Basic Lookups
dig example.com A
dig example.com AAAA
dig example.com MX
dig example.com TXT
dig +short example.com A
Name the domain, then the record type. Without a type, dig asks for an A record. +short prints only the values, one per line, which is handy in scripts. What each record type means is covered in DNS record types explained.
Install dig
sudo apt install bind9-dnsutils # Debian and Ubuntu
sudo dnf install bind-utils # AlmaLinux and Rocky Linux
On Debian and Ubuntu, the older name dnsutils still installs the same package. Both commands also install nslookup and host.
Read the Full Output
A plain dig example.com prints several sections:
- Header: the
statusfield is the result.NOERRORmeans the query worked,NXDOMAINmeans the name does not exist, andSERVFAILmeans the server could not get an answer. - Flags:
aameans the answer came from an authoritative server for the zone; without it, the answer came from a resolver. - QUESTION: what was asked.
- ANSWER: the records, with name, TTL, class, type, and value.
- Footer: the query time and the
SERVERthat answered.
For only the answer lines with their TTL, turn everything off and the answer back on:
dig example.com MX +noall +answer
Read the TTL
The second column of an answer line is the TTL in seconds. From an authoritative server it is the value set in the zone. From a resolver it is the time left before the cached copy expires, so it counts down between queries. If you changed a record and still see the old value, the TTL tells you how long caches may keep it.
Ask a Specific DNS Server
dig example.com @resolver_ip
dig example.com A @resolver_ip +short
Replace resolver_ip with the address of the server to ask. By default dig uses the resolver in /etc/resolv.conf. Asking a public resolver shows what the internet sees; asking the domain's own name server, whose names dig example.com NS +short lists, shows what the zone really contains, without any cache.
Follow the Chain with +trace
dig example.com +trace
+trace starts at the root servers and follows each delegation: root, then the top-level domain, then the domain's name servers. After it gets the list of root servers, it asks each server itself instead of relying on your resolver's cache, so it shows where a broken delegation or a wrong NS record sits. It needs outgoing DNS traffic to the internet to be allowed.
Reverse Lookups
dig -x 203.0.113.10
dig -x 203.0.113.10 +short
-x turns the address into a PTR query under in-addr.arpa, or ip6.arpa for an IPv6 address. Why mail servers care about the answer is in what is reverse DNS.
Troubleshooting with dig
| Result | Meaning |
|---|---|
NXDOMAIN | The name does not exist. Check spelling and the zone. |
NOERROR, empty answer | The name exists, but has no record of that type. |
SERVFAIL | The resolver failed; try +trace. |
| Timed out | No server answered; check the network and firewall. |
dig asks DNS directly and ignores /etc/hosts, so it can disagree with what applications on the same server see. If the answer is right but a browser still fails, see DNS_PROBE_FINISHED_NXDOMAIN; if the server itself cannot resolve names, see temporary failure in name resolution. A simpler tool for quick checks is nslookup.