The DIG command is a tool for querying DNS nameservers for information about host addresses, mail exchange servers, nameservers, and other related information. This tool can be used from any Linux/Unix or macOS operating system.
The most typical use of the dig command is to simply query a single host.
In this KB article, we’ll explain how to read the output of the dig command and how to use the command.
How to use the DIG command #
What can I learn using the dig command? #
dig will let you perform any valid DNS query, the most common of which are:
- A (the IP address)
- TXT (text annotations)
- MX (mail exchanges)
- NS (nameservers)
Run the Command #
- First, open your SSH client and open a connection to your hosting account or any system where you have a console/command line in which you can input commands. If you aren’t familiar with connecting to your hosting account with SSH, click here to review our Knowledgebase Article on the subject.
- Once you have your connection open, enter the command as:
dig domain.tld where domain.tld is the domain and extension you’re querying.
Struggling with DNS issues? ChemiCloud is the hosting solution designed to save you time! 🤓 Check out our web hosting plans!
Examine the Output #
[yourcpusercc@rs2-dal ~]$ dig cchostingdemos.com ; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.4 <<>> cchostingdemos.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52628 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;cchostingdemos.com. IN A ;; ANSWER SECTION: cchostingdemos.com. 300 IN A 104.21.69.5 cchostingdemos.com. 300 IN A 172.67.202.37 ;; Query time: 7 msec ;; SERVER: 198.58.107.5#53(198.58.107.5) ;; WHEN: Tue Apr 06 22:21:26 EDT 2021 ;; MSG SIZE rcvd: 79
The opening section of the output tells us a little bit about itself:
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.4 <<>> cchostingdemos.com
The Got answer section tells us some technical details about the answer received from the DNS Server.
;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52628 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
The Question section serves to remind us of our query. The default query is for an Internet address (A).
;; QUESTION SECTION: ;cchostingdemos.com. IN A
The answer section is where the answer to our query is given.
;; ANSWER SECTION: cchostingdemos.com. 300 IN A 104.21.69.5 cchostingdemos.com. 300 IN A 172.67.202.37
The final section of the default output contains statistics about the query.
;; Query time: 7 msec ;; SERVER: 198.58.107.5#53(198.58.107.5) ;; WHEN: Tue Apr 06 22:21:26 EDT 2021 ;; MSG SIZE rcvd: 79
Quick dig commands you should know #
- A quick way to get just the answer and not the fluff around it is to run:
dig domain.tld +short
- Use this command to get the addresses for a domain:
dig domain.tld A +noall +answer
- Use this command to get a list of all of the mail servers for a domain:
dig domain.tld MX +noall +answer
- Use this command to get a list of authoritative DNS servers for a domain:
dig domain.tld NS +noall +answer
- Use this command to get a list of all of the above in one convenient set of results:
dig domain.tld ANY +noall +answer
- Use this command to query A record of a domain using a specific nameserver:
dig A domain.tld @ns1.chemicloud.com +short
- Use the following to trace the path taken:
dig domain.tld +trace
That’s a wrap! Now you know how to master the DIG command using your terminal.