A Beginner's Guide to Using the `dig` Command in Linux
digMost 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 dnsutilssudo yum install bind-utilssudo pacman -S bind-toolsdigThe simplest way to use dig is to query a domain’s DNS records:
dig example.comThis 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: 56dig Use CasesBy default, dig fetches the A record, but you can specify other record types:
dig example.com MXdig example.com NSdig example.com TXTdig www.example.com CNAMEBy 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.comIf you only want the answer section, use +short:
dig example.com +shortOutput:
93.184.216.34To see the full DNS resolution path (similar to traceroute for DNS):
dig +trace example.comFind the domain associated with an IP address:
dig -x 93.184.216.34dig Optionsdig example.com +noall +answerdig example.com +tcpdig example.com +time=3The 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!