Quick take: The dig command queries DNS. dig example.com looks up the A record; add a type like dig example.com MX for mail records, +short for a clean answer, and @8.8.8.8 to query a specific server.
Introduction
The dig command (domain information groper) is the administrator's DNS tool, giving precise control over lookups and detailed output. It queries any record type, can ask a specific DNS server, and shows the full response — making it far better than a browser for diagnosing DNS problems.
This guide covers looking up common record types, getting concise output, querying specific resolvers, and tracing how a name is resolved.
Syntax
The basic syntax of the dig command is:
dig [@SERVER] DOMAIN [TYPE] [+OPTIONS]Common Options and Parameters
The most useful options and parameters for the dig command:
| Option | Description |
|---|---|
| TYPE | Record type: A, AAAA, MX, TXT, NS, CNAME, SOA. |
| @server | Query a specific DNS server (e.g. @8.8.8.8). |
| +short | Print only the answer, nothing else. |
| +noall +answer | Show just the answer section. |
| -x IP | Reverse lookup — find the hostname for an IP. |
| +trace | Trace the full delegation from the root servers. |
| +stats | Show query timing and statistics. |
Practical Examples
Real dig commands you can run today:
# Look up the A record
dig example.com
# Get just the IP address
dig +short example.com
# Look up mail (MX) records
dig example.com MX +short
# Look up TXT records (SPF, verification)
dig example.com TXT +short
# Query a specific DNS server
dig @1.1.1.1 example.com
# Reverse lookup an IP
dig -x 8.8.8.8 +short
# Trace the full resolution path
dig +trace example.comTips and Best Practices
dig +shortgives a clean, scriptable answer — perfect when you only want the value.- Use
@8.8.8.8to bypass your local resolver and test whether a record has propagated publicly. dig +tracewalks the delegation from the root down, which is the best way to debug where resolution breaks.
Final Thoughts
dig is the definitive DNS troubleshooting tool — querying any record type, any server, with output you control. Learn +short for clean answers, record types like MX and TXT, and @server to test propagation. When a site will not resolve or email is bouncing, dig shows you exactly what DNS is returning.
FAQ: dig Command in Linux
How do I look up a domain's IP with dig?+
Run dig example.com for the full response, or dig +short example.com to print just the IP address. Add the record type to query others.
How do I check MX records with dig?+
Use dig example.com MX +short to list the mail servers for a domain. This is the quickest way to verify email routing.
How do I query a specific DNS server?+
Prefix the server with @: dig @8.8.8.8 example.com asks Google's resolver directly, which is useful for checking whether a DNS change has propagated.
How do I do a reverse DNS lookup?+
Use -x with the IP: dig -x 8.8.8.8 +short returns the hostname associated with that address through PTR records.
What is the difference between dig and nslookup?+
dig gives detailed, scriptable output and fine control over record types and servers, and is preferred by administrators. nslookup is simpler and interactive but less precise, though it is still common on Windows.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support