linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Commands/cmd-dig

kb/commands ── Commands ── beginner

dig: DNS queries with full detail

dig queries DNS. Ask for any record type from any server. +short gives compact output. +trace follows resolution from the root. +dnssec shows DNSSEC signatures. It replaces nslookup for debugging.

view as markdownaka: dig, cmd-host, cmd-nslookup

Basic syntax

dig [@server] [name] [type] [+option ...]

By default, dig queries the A record using the resolver from /etc/resolv.conf:

bash
$ dig example.com
;; ANSWER SECTION:
example.com.   3600  IN  A  93.184.216.34

Common record types

TypeWhat it holds
AIPv4 address
AAAAIPv6 address
CNAMEalias to another name
MXmail server
NSname server for the zone
TXTarbitrary text records (SPF, DKIM, verification tokens)
SOAstart of authority: zone parameters
PTRreverse lookup: IP to name
CAAwhich CAs may issue a certificate for the domain
SRVservice location (SIP, XMPP, MS AD)
DS / DNSKEYDNSSEC
bash
dig example.com AAAA       # IPv6
dig example.com MX         # mail servers
dig example.com TXT        # SPF, DKIM
dig example.com NS         # authoritative NS
dig example.com ANY        # everything available (ChannelBind may reject this)

+short: the quick answer

The default output is verbose. +short keeps only the answer:

bash
$ dig example.com +short
93.184.216.34
$ dig example.com MX +short
10 mail.example.com.
20 backup-mail.example.com.

Handy in scripts, but too terse for debugging.

Choosing a server

bash
dig @8.8.8.8 example.com           # query Google DNS
dig @1.1.1.1 example.com           # query Cloudflare
dig @ns1.example.com example.com   # query the authoritative server

Without @, dig uses /etc/resolv.conf. This matters during debugging: a local resolver may be returning a cached stale answer.

+trace: the full resolution path

Shows each hop from the root down to the authoritative server:

bash
$ dig example.com +trace
;; .             root NS
;; com.          .com TLD NS
;; example.com.  authoritative NS
;; example.com.  93.184.216.34

Each hop is a separate non-recursive query. When something "works here but not there," +trace shows exactly where the chain breaks.

Reverse DNS

bash
dig -x 93.184.216.34
;; ANSWER:
34.216.184.93.in-addr.arpa.  PTR  example.com.

PTR records live in the in-addr.arpa zone. They are often out of sync with the A record (forward says one thing, reverse says another).

DNSSEC

bash
dig example.com +dnssec

Shows RRSIG (signatures). +sigchase follows the chain of trust from the root. Useful when DNSSEC validation fails and you need to locate the break.

Useful options

OptionWhat it does
+shortcompact output
+tracefull resolution path from root
+dnssecshow RRSIG records
+tcpuse [[tcp-handshake
+notcpUDP only
+nostatsomit the stats footer
+nocommentssuppress ;; comment lines
+noall +answerminimal: ANSWER section only
+time=3 +tries=13-second timeout, one attempt
+norecnon-recursive query (for authoritative servers)
-p 5353alternate port (mDNS)

A useful pattern

To see only the TTL and value:

bash
dig example.com +noall +answer
example.com.    3600  IN  A  93.184.216.34

If the TTL drops between queries, the resolver is caching. If it stays at 3600, you are getting a cache hit.

Query all types in parallel

bash
for t in A AAAA MX NS TXT CAA SOA; do
    echo "=== $t ==="
    dig example.com $t +short
done

Troubleshooting

connection timed out; no servers could be reached

The resolver is unreachable. Check /etc/resolv.conf, the firewall, and the network path.

SERVFAIL

The authoritative server returned an error. Often a DNSSEC validation problem, or the upstream resolver has a stuck query. Try dig @8.8.8.8 to query a different resolver.

NXDOMAIN

The domain does not exist. Check for a typo in the name, or the zone may not have been delegated yet.

REFUSED

The server will not answer this query (it does not allow external recursion). This is normal for authoritative servers. Query them only for their own zones.

Alternatives

  • host: simpler output, no auxiliary information
  • nslookup: older, but familiar on Windows and macOS
  • drill (LDNS): a modern replacement for dig from the same NLnet team, but dig is available everywhere

§ команды

bash
dig example.com +short

A record only, no extra output

bash
dig @8.8.8.8 example.com

Query a specific resolver to confirm the problem is not local

bash
dig example.com +trace

Full resolution path from root NS, shows where the chain breaks

bash
dig -x 8.8.8.8

Reverse DNS for an IP: what name is registered

bash
dig example.com NS +short

Which name servers are authoritative for the zone

bash
dig example.com TXT +short | grep -i spf

SPF record: which mail servers may send from this domain

bash
dig +noall +answer +nostats example.com

ANSWER section only, clean output for scripts and dashboards

§ см. также

  • dns-resolutionDNS: ResolutionName-to-IP resolution goes through NSS: first `/etc/hosts`, then DNS via `/etc/resolv.conf`. The order is set in `/etc/nsswitch.conf`.
  • bind-dns-serverBIND: Authoritative and Caching DNS ServerBIND (Berkeley Internet Name Domain) is the most widely deployed DNS server on Linux. The daemon is `named`, the config is `/etc/named.conf` or `/etc/bind/named.conf`, and control goes through `rndc`.
  • portPort: How Multiple Services Share One IPA 16-bit number (0-65535) that identifies the **destination process** on a host. IP says which host; port says which process. 80 is HTTP, 443 is HTTPS, 22 is SSH.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies