A Beginner's Guide to Using the `dig` Command in Linux
dig
Most Linux distributions come with dig
pre-installed as part of the BIND DNS utilities. If it's not available, you can install it with:
sudo apt install dnsutils
sudo yum install bind-utils
sudo pacman -S bind-tools
dig
The simplest way to use dig
is to query a domain’s DNS records:
dig example.com
This will return the A record (IPv4 address) of example.com
along with additional DNS response details.
A typical dig
response includes:
Example output:
; <<>> DiG 9.16.1-Ubuntu <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 3600 IN A 93.184.216.34
;; Query time: 10 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Fri Apr 04 12:00:00 UTC 2025
;; MSG SIZE rcvd: 56
dig
Use CasesBy default, dig
fetches the A record, but you can specify other record types:
dig example.com MX
dig example.com NS
dig example.com TXT
dig www.example.com CNAME
By default, dig
uses your system's DNS resolver. To query a specific DNS server (like Google’s 8.8.8.8
):
dig @8.8.8.8 example.com
If you only want the answer section, use +short
:
dig example.com +short
Output:
93.184.216.34
To see the full DNS resolution path (similar to traceroute
for DNS):
dig +trace example.com
Find the domain associated with an IP address:
dig -x 93.184.216.34
dig
Optionsdig example.com +noall +answer
dig example.com +tcp
dig example.com +time=3
The dig
command is an essential tool for network administrators, developers, and anyone working with DNS. With its flexibility and detailed output, you can quickly diagnose DNS issues, verify records, and troubleshoot connectivity problems.
Try experimenting with the examples above, and soon you’ll be a dig
expert!
Got questions or tips? Drop them in the comments below!
Would you like me to add anything else, like troubleshooting tips or real-world examples? Let me know!