$linuxjunkies
>

dig(1)

Query DNS servers to look up domain names, IP addresses, and other DNS records.

UbuntuDebianFedoraArch

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

FlagWhat it does
+shortDisplay only the answer section in minimal format, suppressing headers and extra information
+noall +answerShow only the answer section; useful for scripting and clean output
-xPerform reverse DNS lookup (PTR query) for an IP address
+traceTrace the path from root nameserver down to the authoritative nameserver
+recurse / +norecurseEnable or disable recursive queries (default: recursive)
-t TYPESpecify the DNS record type to query (A, AAAA, MX, NS, TXT, SOA, CNAME, etc.)
@serverQuery a specific nameserver instead of the default resolver
+statsDisplay statistics about the query, including query time and message size
-4 / -6Force IPv4 or IPv6 queries respectively
+multilinePrint records in expanded multiline format with descriptive comments

Examples

Query the default nameservers for the A record of example.com

dig example.com

Look up MX (mail exchange) records for example.com

dig example.com MX

Query Google's public DNS (8.8.8.8) for example.com and show only the answer

dig @8.8.8.8 example.com +short

Perform reverse DNS lookup on IP address 192.0.2.1 to find its hostname

dig -x 192.0.2.1

Trace the full DNS lookup path from root nameserver to authoritative server

dig example.com +trace

Query NS (nameserver) records for example.com and display only the answer section

dig example.com NS +noall +answer

Retrieve all available DNS records for example.com (all record types)

dig example.com ANY

Query a specific nameserver and include query statistics in the output

dig @ns1.example.com example.com +stats

Related commands