Table of Contents
The dig command is a must-know DNS troubleshooting tool for Linux users, system admins, and network engineers. Whether you’re running Ubuntu or Debian, dig helps you query DNS servers, trace the path of a domain resolution, and even check MX records for emails. According to Red Hat, dig is more powerful and flexible than older tools like nslookup. Here’s how to make the most of it.
What Does the dig Command Do?
The dig (Domain Information Groper) command queries DNS name servers. It’s used to troubleshoot DNS issues, gather domain information, and display detailed data like A, MX, TXT, and NS records. dig is popular due to its clarity, scripting compatibility, and support for advanced DNS queries.
How to Install dig on Linux
Before using dig command, make sure it’s installed. On many Linux distributions, it’s not available by default. Here’s how to install it based on your system:
Linux Distribution | Command to Install dig |
---|---|
Ubuntu | sudo apt install dnsutils |
Debian | sudo apt-get install dnsutils |
CentOS / RHEL | sudo yum install bind-utils |
Once installed, test it by typing dig example.com
in the terminal.
1. How to Use dig command in CMD (Linux Terminal)
You can use dig like this: dig domainname
. For example:
dig google.com
This returns the IP address of Google.com’s DNS servers. The key sections include QUESTION, ANSWER, AUTHORITY, and ADDITIONAL.
2. What Does dig 8.8.8.8 Do?
dig -x 8.8.8.8
performs a reverse DNS lookup on Google’s public DNS IP. It returns associated domain name(s).
If you instead run dig 8.8.8.8
(without the -x flag), it treats 8.8.8.8 like a hostname, not an IP, and it won’t return meaningful data.
3. What’s the Difference Between dig and nslookup?
Both are DNS query tools, but dig is more modern and flexible. Here’s a comparison:
Feature | dig | nslookup |
---|---|---|
Modern Support | Yes | Deprecated in many cases |
Scripting-friendly | Yes | No |
Output Clarity | High | Medium |
If you’re still using nslookup, you can install it with apt-get nslookup
or install nslookup ubuntu
depending on your setup.
4. How to Use dig to Trace DNS Paths
The +trace
option lets you see each step in DNS resolution from root to authoritative name servers:
dig +trace example.com
This is useful for DNS diagnostics and understanding how domain resolution works behind the scenes.
5. Query Specific DNS Record Types
dig example.com MX
– Email recordsdig example.com TXT
– Text records (SPF, DKIM)dig example.com NS
– Name server information
This helps when verifying DNS changes for email setup, CNAME validation, or domain delegation.
6. Use dig command with a Specific DNS Server
Need to test how a specific DNS resolver behaves? Use:
dig @1.1.1.1 example.com
This sends the query straight to Cloudflare’s DNS server 1.1.1.1. It’s useful when debugging propagation.
7. dig for Reverse DNS Lookups
To find out what domain is associated with an IP address:
dig -x 142.250.190.78
This can tell you whether mail servers are configured correctly with PTR records.
8. How to Use dig Non-Interactively
To integrate dig into scripts:
dig +short example.com
– Outputs only the IP address.dig -t MX example.com +short
– Only MX records.
This makes dig ideal for CI/CD scripts or monitoring tools.
9. Analyzing DNS Propagation with dig
When changing DNS records, use dig with multiple public resolvers (e.g., Google’s 8.8.8.8, Cloudflare’s 1.1.1.1) to check propagation:
dig @8.8.8.8 yourdomain.com
dig @1.1.1.1 yourdomain.com
This verifies if your DNS changes are live across the internet.
FAQ: Common Questions About the dig Command
How do I install dig on Ubuntu?
Run sudo apt install dnsutils
. It will add dig to your system.
Is dig available on macOS?
Yes, macOS includes dig by default. You can use it directly from Terminal.
Why is dig better than nslookup?
dig provides clearer output, scriptable results, and better support for modern DNS features.
Can I check DNS propagation with dig?
Yes. Query different DNS servers (like @8.8.8.8
, @1.1.1.1
) to see if your changes have propagated.
Is there a GUI alternative to dig?
Yes, online DNS lookup tools like WhatsMyDNS or Google Admin Toolbox DIG act as web-based dig utilities.
Final Thoughts
Now that you’ve learned how to use the dig command for everything from DNS lookups to reverse IP tracing, you can confidently troubleshoot domain issues in Linux. Whether you’re managing servers, migrating domains, or investigating DNS problems, dig is an essential tool to add to your toolkit.