The dig
(Domain Information Groper) command is a powerful tool for querying DNS information. Here is a guide on how to use dig
to retrieve various types of DNS records:
-
On Ubuntu/Debian:
sudo apt-get update sudo apt-get install dnsutils
-
On CentOS/RHEL:
sudo yum install bind-utils
-
On macOS:
brew install bind
-
On Windows:
dig
can be used via the BIND package or using tools like Cygwin or Windows Subsystem for Linux (WSL).
-
Retrieve A Record (IP address of the domain):
dig example.com
-
Retrieve MX Records (Mail Exchange records):
dig example.com MX
-
Retrieve NS Records (Name Server records):
dig example.com NS
-
Retrieve TXT Records (Text records):
dig example.com TXT
-
Retrieve CNAME Records (Canonical Name records):
dig example.com CNAME
-
Specify a Different DNS Server:
dig @8.8.8.8 example.com
This uses Google’s public DNS server (8.8.8.8).
-
Retrieve SOA Record (Start of Authority record):
dig example.com SOA
-
Retrieve All DNS Records:
Retrieve All DNS Records:
-
Reverse DNS Lookup (finding the domain name associated with an IP address):
dig -x 192.0.2.1
-
Retrieve DNSSEC Information:
dig example.com +dnssec
-
Short Output:
dig example.com +short
-
Detailed Output:
dig example.com +multiline
-
Output Only Answer Section:
dig example.com +noall +answer
-
Verbose Output:
dig example.com +noall +answer +authority +additional
-
Redirect Output to a File:
dig example.com > output.txt
-
Append Output to a File:
dig example.com >> output.txt
-
Retrieve A Record:
dig openai.com
Output:
-
Retrieve MX Record:
dig openai.com MX
; <<>> DiG 9.16.1-Ubuntu <<>> openai.com MX ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 67890 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 3 ;; QUESTION SECTION: ;openai.com. IN MX ;; ANSWER SECTION: openai.com. 300 IN MX 10 mail.openai.com. openai.com. 300 IN MX 20 backup.openai.com. ;; AUTHORITY SECTION: example.com. 86400 IN NS ns1.example.com. example.com. 86400 IN NS ns2.example.com. ;; ADDITIONAL SECTION: mail.openai.com. 300 IN A 192.0.2.100 backup.openai.com. 300 IN A 192.0.2.200 ns1.example.com. 172800 IN A 192.0.2.1 ns2.example.com. 172800 IN A 192.0.2.2 ;; Query time: 20 msec ;; SERVER: 192.0.2.53#53(192.0.2.53) ;; WHEN: Mon Jun 01 12:45:00 UTC 2024 ;; MSG SIZE rcvd: 234
; <<>> DiG 9.16.1-Ubuntu <<>> openai.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 3
;; QUESTION SECTION:
;openai.com. IN A
;; ANSWER SECTION:
openai.com. 300 IN A 192.0.2.123
;; AUTHORITY SECTION:
example.com. 86400 IN NS ns1.example.com.
example.com. 86400 IN NS ns2.example.com.
;; ADDITIONAL SECTION:
ns1.example.com. 172800 IN A 192.0.2.1
ns2.example.com. 172800 IN A 192.0.2.2
;; Query time: 10 msec
;; SERVER: 192.0.2.53#53(192.0.2.53)
;; WHEN: Mon Jun 01 12:34:56 UTC 2024
;; MSG SIZE rcvd: 123
The dig
command is a versatile and powerful tool for querying DNS information. It allows you to retrieve various DNS records, use specific DNS servers, format output, and more. This guide provides a solid foundation for using dig
effectively to gather DNS information.