DEV Community

Safal Bhattarai
Safal Bhattarai

Posted on

Linux dig Command: Simple DNS Lookup Examples

The dig (Domain Information Groper) command helps developers check DNS records and troubleshoot domain resolution on Linux. It is one of the first tools to reach for when a domain isn't behaving the way you expect.

1. Install dig

On Debian/Ubuntu-based systems, dig ships in the dnsutils package:

sudo apt update
sudo apt install dnsutils
Enter fullscreen mode Exit fullscreen mode

2. Find a Domain's IP Address

dig safal.me +short
Enter fullscreen mode Exit fullscreen mode

The +short flag trims the output down to just the IP addresses found in the DNS response.

3. Check DNS Records

Pass a record type after the domain name:

dig safal.me A
dig safal.me AAAA
dig safal.me MX
dig safal.me NS
dig safal.me TXT
Enter fullscreen mode Exit fullscreen mode
Record Purpose
A IPv4 address
AAAA IPv6 address
MX Mail servers
NS Name servers
TXT Text records (SPF, domain verification, etc.)

4. Query a Specific DNS Server

dig @8.8.8.8 safal.me
Enter fullscreen mode Exit fullscreen mode

This sends the query to Google's public DNS resolver instead of your system default, which is handy for checking whether a problem is local to your resolver.

5. Trace DNS Resolution

dig safal.me +trace
Enter fullscreen mode Exit fullscreen mode

This shows the delegation process step by step, from the root servers down to the domain's authoritative name servers.

Conclusion

The dig command is a useful tool for developers and DevOps engineers troubleshooting DNS issues. Once you know these few flags, most DNS debugging becomes quick and predictable.

Next: Linux nslookup Command: Simple Examples.


About Me

I'm Safal Bhattarai, a Tech Lead, Full Stack Developer, and DevOps Engineer.

🌐 Website GitHub

Top comments (1)

Collapse
 
coder-safal profile image
Safal Bhattarai •

Tip: You can use dig +short yourdomain.com to quickly check the IP address returned by DNS.

What Linux networking command should I cover next — nslookup, ping, or traceroute?