dig Command Reference

Complete reference for dig command syntax, DNS query types, command-line flags, and query options with defaults and examples.

Complete reference for Domain Information Groper (dig) command syntax, DNS record types, command-line flags, and query options.

dig Command Syntax

Domain Information Groper (dig) follows this command-line syntax:

dig [@server] [-b address] [-c class] [-f filename] [-k filename] [-p port#] [-q name] [-t type] [-x addr] [-4] [-6] [name] [type] [class] [queryopt...]

A typical dig invocation uses the pattern dig @server name type, where @server is the DNS resolver to query, name is the domain to look up, and type is the DNS record type.

dig DNS Record Types

dig queries different DNS record types to retrieve specific domain information. Specify the record type after the domain name in the dig command.

Record TypeDescriptionExample
AMaps a domain name to an IPv4 address. The default record type when no type is specified.dig example.com A
AAAAMaps a domain name to an IPv6 address. Use to verify IPv6 connectivity for a domain.dig example.com AAAA
MXLists the Mail Exchange servers responsible for receiving email for a domain, with priority values.dig example.com MX
NSLists the authoritative nameservers delegated to handle DNS for a domain.dig example.com NS
CNAMEReturns the Canonical Name record that aliases one domain name to another.dig www.example.com CNAME
SOAReturns the Start of Authority record containing the primary nameserver, administrator email, zone serial number, refresh interval, retry interval, expire time, and minimum TTL.dig example.com SOA
TXTReturns text records used for SPF policies, DKIM keys, domain verification, and other metadata.dig example.com TXT
PTRReturns the Pointer record that maps an IP address to a domain name (reverse DNS lookup). Typically queried with dig -x.dig -x 93.184.216.34
SRVReturns the Service Locator record specifying the host, port, priority, and weight for a network service.dig _sip._tcp.example.com SRV
ANYRequests all available record types for a domain. Some DNS servers restrict ANY queries for security reasons.dig example.com ANY

dig Command-Line Flags

dig accepts command-line flags that control query transport, source address, and input mode. These flags use the traditional hyphen prefix.

FlagDescriptionDefaultExample
@serverSpecify the DNS server to query by IP address or hostname, bypassing the system resolver in /etc/resolv.confSystem resolverdig @8.8.8.8 example.com
-b addressSet the source IP address for the outgoing DNS query. The address must be valid on the host network interface.System defaultdig -b 192.168.1.10 example.com
-c classSet the query class. Common values: IN (Internet), CH (CHAOSNET), HS (Hesiod).INdig example.com -c CH
-f fileRead domain names from a file and query each one in batch mode, one domain per line.N/Adig -f domains.txt
-k fileSpecify a TSIG (Transaction Signature) key file to sign DNS queries for authenticated transfers.Nonedig -k tsig.key example.com AXFR
-p portSend the DNS query to a non-standard port number instead of the default DNS port.53dig -p 5353 example.com
-q nameSet the query domain name explicitly. Useful when the domain name could be confused with a dig option.N/Adig -q example.com
-t typeSet the DNS record type for the query (A, AAAA, MX, NS, CNAME, TXT, SOA, PTR, SRV, ANY).Adig -t MX example.com
-x addressPerform a reverse DNS lookup for the specified IP address. dig converts the address to a PTR query automatically.N/Adig -x 8.8.8.8
-4Force dig to use IPv4 transport only for sending the query.Both IPv4 and IPv6dig -4 example.com
-6Force dig to use IPv6 transport only for sending the query.Both IPv4 and IPv6dig -6 example.com

dig Query Options (+ Prefix)

dig query options use the + prefix and control output formatting, DNS protocol flags, and timeout behavior. Prefix any option with no to disable it (e.g., +nostats).

dig Output Control Options

These dig options control which sections of the DNS response appear in the output.

OptionDescriptionDefaultExample
+[no]shortDisplay the answer value only, without headers, metadata, or statistics. Useful for scripting.Offdig example.com +short
+[no]allEnable or disable all display sections at once. Combine with +answer to show the answer section alone.Ondig example.com +noall +answer
+[no]answerControl display of the ANSWER section containing the returned DNS records.Ondig example.com +noanswer
+[no]authorityControl display of the AUTHORITY section listing authoritative nameservers for the domain.Ondig example.com +noauthority
+[no]additionalControl display of the ADDITIONAL section containing supplementary records.Ondig example.com +noadditional
+[no]questionControl display of the QUESTION section repeating the sent query.Ondig example.com +noquestion
+[no]commentsControl display of comment lines showing packet header details and section names.Ondig example.com +nocomments
+[no]statsControl display of the statistics footer with query time, server IP, and message size.Ondig example.com +nostats
+[no]cmdControl display of the initial comment line showing the dig version and command.Ondig example.com +nocmd
+[no]ttlidControl display of the Time to Live (TTL) value in record output.Ondig example.com +nottlid
+[no]ttlunitsDisplay TTL values in human-readable units (s, m, h, d, w) instead of raw seconds.Offdig example.com +ttlunits
+[no]classControl display of the record class (IN, CH, HS) in output.Ondig example.com +noclass
+[no]multilinePrint SOA and other complex records in a multi-line format with comments for readability.Offdig example.com SOA +multiline
+[no]yamlPresent the DNS query results in YAML format for machine parsing.Offdig example.com +yaml
+[no]cryptoControl display of cryptographic fields in DNSSEC-related records (RRSIG, DNSKEY).Ondig example.com +dnssec +nocrypto
+[no]rrcommentsControl display of per-record comments in the output.Offdig example.com +rrcomments
+[no]split=NSplit hexadecimal and Base64 fields into chunks of N characters for readability.56dig example.com DNSKEY +split=32
+[no]identifyShow the responding server's IP address and port in short-form answers. Useful with multiple queries.Offdig example.com +short +identify

dig DNS Protocol Options

These dig options modify the DNS query behavior and protocol flags sent to the nameserver.

OptionDescriptionDefaultExample
+[no]traceTrace the DNS delegation path from root nameservers through TLD servers to the authoritative server. Disables recursion automatically.Offdig example.com +trace
+[no]recurseSet or clear the RD (Recursion Desired) flag in the query. Disabling recursion sends a non-recursive query.Ondig example.com +norecurse
+[no]dnssecRequest DNSSEC records (RRSIG, DNSKEY) to verify the cryptographic signatures of DNS responses.Offdig example.com +dnssec
+[no]adflagSet or clear the AD (Authentic Data) flag requesting DNSSEC validation status from the resolver.Ondig example.com +noadflag
+[no]cdflagSet or clear the CD (Checking Disabled) flag requesting the resolver to skip DNSSEC validation.Offdig example.com +cdflag
+[no]aaflagSet the AA (Authoritative Answer) flag in the outgoing query.Offdig example.com +aaflag
+[no]tcpForce dig to use TCP instead of UDP for the DNS query. Alias: +[no]vc.Off (UDP)dig example.com +tcp
+[no]ignoreDo not fall back to TCP when the DNS response has the TC (Truncation) flag set.Offdig example.com +ignore
+[no]cookieSend an EDNS COOKIE option with the query for DNS cookie authentication.Ondig example.com +nocookie
+[no]edns[=N]Set the EDNS version to N. Use +noedns to disable EDNS entirely.0dig example.com +noedns
+[no]nsidRequest the Name Server Identifier (NSID) from the responding DNS server.Offdig example.com +nsid
+[no]nssearchSearch for all authoritative nameservers for a domain and display the SOA record from each.Offdig example.com +nssearch
+[no]searchUse the search list defined in /etc/resolv.conf to complete unqualified domain names.Offdig myhost +search
+[no]qrPrint the outgoing query before sending it. Useful for debugging the exact query being sent.Offdig example.com +qr
+[no]failDo not fall back to the next nameserver if the current one returns SERVFAIL.Offdig example.com +fail
+[no]besteffortAttempt to parse and display malformed or non-standard DNS messages.Offdig example.com +besteffort
+subnet=addrSet the EDNS Client Subnet option to specify the client's network for geolocation-aware DNS responses.Nonedig example.com +subnet=203.0.113.0/24
+[no]keepopenKeep the TCP socket open between consecutive queries in batch mode.Offdig -f domains.txt +tcp +keepopen
+[no]keepaliveRequest EDNS TCP keepalive from the DNS server to maintain the connection.Offdig example.com +tcp +keepalive
+domain=nameSet the default domain name for unqualified lookups.Nonedig myhost +domain=example.com
+[no]mappedAllow mapped IPv4-over-IPv6 addresses in query transport.Offdig example.com +mapped
+[no]header-onlySend a query with only the DNS header and no question section.Offdig example.com +header-only
+[no]opcode=NSet the opcode in the DNS query header (0=QUERY, 1=IQUERY, 2=STATUS, 4=NOTIFY, 5=UPDATE).0dig example.com +opcode=0
+[no]zflagSet the reserved Z flag in the DNS header. Used for protocol testing.Offdig example.com +zflag
+[no]badcookieRetry the query when the server responds with BADCOOKIE.Ondig example.com +nobadcookie
+[no]expandaaaaExpand AAAA records to display the full 128-bit IPv6 address without abbreviation.Offdig example.com AAAA +expandaaaa
+[no]unexpectedAccept DNS responses from servers that are not the one queried.Offdig example.com +unexpected
+[no]unknownformatPrint RDATA in the generic RFC 3597 format for unknown record types.Offdig example.com TYPE65 +unknownformat
+padding=NSet the EDNS padding block size to N bytes to mask query length in encrypted DNS.0dig example.com +padding=128

dig Timeout and Retry Options

These dig options control how long dig waits for a response and how many times it retries a failed query.

OptionDescriptionDefaultExample
+time=NSet the query timeout to N seconds. Increase for slow or distant DNS servers.5dig example.com +time=10
+tries=NSet the total number of UDP query attempts, including the initial query.3dig example.com +tries=5
+retry=NSet the number of UDP retries after the initial query fails. Unlike +tries, this does not count the first attempt.2dig example.com +retry=4
+ndots=NSet the number of dots required in a domain name before it is treated as an absolute name. Names with fewer dots use the search list.Value from /etc/resolv.conf or 1dig myhost +ndots=2
+bufsize=NSet the UDP message buffer size announced via EDNS. Controls the maximum UDP payload size dig accepts.1232dig example.com +bufsize=4096

dig Help and Version

dig displays a usage summary with all supported flags and options using the -h flag:

dig -h

dig prints its version number and BIND build details with the -v flag:

dig -v