dig ("domain information groper") is the de-facto DNS diagnostic tool on Linux. It performs DNS queries and prints the raw response (question, answer, authority, and additional sections), making it invaluable for debugging DNS problems.
dig example.com # A record
dig example.com MX # mail servers
dig example.com AAAA # IPv6
dig example.com NS # authoritative nameservers
dig @8.8.8.8 example.com # query a specific resolver
dig +short example.com # just the answer, no ceremony
dig +trace example.com # follow the delegation chain from the root
dig -x 93.184.216.34 # reverse lookup (PTR)
dig comes from the BIND project. Alternatives: host (simpler output), nslookup (older, still widely used), and drill (from ldns, common on Alpine).
Discussed in:
- Chapter 12: Networking — DNS