DIG quick start tutorial for DNS Lookup

Dig (Domain information groper) can be used to do DNS lookup on Linux, Mac or windows machine. It will connect a DNS server (default or specified on command line) and look up the IP address, etc. for the given domain. Here are some typical DNS commands using dig. We’ll use Mac for the purpose of this article but these commands should work on Linux and windows also.

Basic dig usage

Run dig with the desired domain as shown below:

$ dig www.infoheap.com
; <<>> DiG 9.8.3-P1 <<>> www.infoheap.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7240
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;www.infoheap.com.		IN	A

www.infoheap.com.	1742	IN	CNAME	infoheap.com.
infoheap.com.		322	IN	A

;; Query time: 135 msec
;; WHEN: Thu Oct 22 21:22:57 2015
;; MSG SIZE  rcvd: 64

Look at the answer section for the outcome. Here we are seeing CNAME and A record entries along with TTL (time to live in seconds) values. Note that dig used the network interface's default DNS server here.

DNS lookup using specific DNS server

Specify DNS server using @ when using dig. Here is the dig command which uses Google's public DNS server

$ dig @ www.infoheap.com
;; Query time: 109 msec
;; WHEN: Fri Oct 23 00:57:00 2015
;; MSG SIZE  rcvd: 64

Note the presence of "SERVER:" in the response as we are using this DNS server for query.

Query mx record

To query mx records (record to specify mail server for the top level domain), you can use type mx as shown below:

$ dig -t mx infoheap.com

Query nameservers for the top level domain

To query nameservers (autorative nameservers for the domain), use the following command:

$ dig -t ns infoheap.com

Query txt records

To query txt records associated with a domain:

$ dig -t txt infoheap.com

Trace DNS delegation path

To trace DNS delegation path, use the following command:

$ dig +trace infoheap.com
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments