How To Use The DIG Command

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

  1. 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.
  2. 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? Zalvis is the hosting solution designed to save you time! 🤓 Check out our web hosting plans!

Examine The Output

[yourcpusercc@rs2-dal ~]$ dig zalvis.com

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.4 <<>> zalvis.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:
;zalvis.com. IN A

;; ANSWER SECTION:
zalvis.com. 300 IN A 104.21.69.5
zalvis.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:
;zalvis.com. IN A

The answer section is where the answer to our query is given.

;; ANSWER SECTION:
zalvis.com. 300 IN A 104.21.69.5
zalvis.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.zalvis.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.

If you enjoyed this article, then you’ll love Zalvis's Cloud Hosting platform. Turbocharge your website and get 24/7 support from our veteran team. Our world-class hosting infrastructure focuses on auto-scaling, performance, and security. Let us show you the Zalvis difference! Check out our services.