dig(1)
Query DNS servers to look up domain names, IP addresses, and other DNS records.
Synopsis
dig [@server] [domain] [type] [+option]...Description
dig (Domain Information Groper) is a flexible command-line tool for querying DNS name servers. It performs DNS lookups and displays answers from name servers in a readable format. Unlike nslookup, dig has a simpler interface and produces more detailed debugging information.
By default, dig queries the system's configured nameservers for A records (IPv4 addresses). You can specify different record types (MX, NS, CNAME, TXT, etc.), query specific nameservers, and use numerous options to control output format and query behavior.
Common options
| Flag | What it does |
|---|---|
+short | Display only the answer section in minimal format, suppressing headers and extra information |
+noall +answer | Show only the answer section; useful for scripting and clean output |
-x | Perform reverse DNS lookup (PTR query) for an IP address |
+trace | Trace the path from root nameserver down to the authoritative nameserver |
+recurse / +norecurse | Enable or disable recursive queries (default: recursive) |
-t TYPE | Specify the DNS record type to query (A, AAAA, MX, NS, TXT, SOA, CNAME, etc.) |
@server | Query a specific nameserver instead of the default resolver |
+stats | Display statistics about the query, including query time and message size |
-4 / -6 | Force IPv4 or IPv6 queries respectively |
+multiline | Print records in expanded multiline format with descriptive comments |
Examples
Query the default nameservers for the A record of example.com
dig example.comLook up MX (mail exchange) records for example.com
dig example.com MXQuery Google's public DNS (8.8.8.8) for example.com and show only the answer
dig @8.8.8.8 example.com +shortPerform reverse DNS lookup on IP address 192.0.2.1 to find its hostname
dig -x 192.0.2.1Trace the full DNS lookup path from root nameserver to authoritative server
dig example.com +traceQuery NS (nameserver) records for example.com and display only the answer section
dig example.com NS +noall +answerRetrieve all available DNS records for example.com (all record types)
dig example.com ANYQuery a specific nameserver and include query statistics in the output
dig @ns1.example.com example.com +stats