The command dig is a tool for querying DNS nameservers for information about host addresses, mail exchanges, nameservers, and related information. This tool can be used from any Linux (Unix) or Macintosh OS X operating system. The most typical use of dig is to simply query a single host.
The dig command fundamentally used for the following purposes:
The basic syntax:
List of DNS record types
Before you use the dig command you should aware of common types of resource records of the DNS. Here are most common resource records:
By default, dig command looks for A records only.
dig command examples
To find the IP address of the host www.cyberciti.biz, type:
Understanding dig command output
The above is simple query for a single host called www.cyberciti.biz. The dig command displays lots of information. Let us try to understand the default dig command output:
More Usage Examples
Here we will teach you how to use dig command through examples.
How do I query a different nameserver such as 126.96.36.199?
You can use @188.8.131.52 as below to query specific nameserver:
The -t option sets the query type to type. It can be any valid query type which is supported in BIND 9. The default query type is "A", unless the -x option is supplied to indicate a reverse lookup. Below is a simple example:
FIND THE IP ADDRESS (A) OF A HOSTNAME
You can use "+short" to show the query result only:
FIND THE HOSTNAME OF AN IP ADDRESS
You can use option -x to carry out the DNS reverse Look-up
FIND THE NS (NAME SERVERS) OF A DOMAIN NAME
You can use query type "NS" as below example:
Real World Case Study - Find Google CDN IP range
Below bash script is from here which is used to dig out all Google CDN IP range:
* Linux and Unix dig Command Examples
* Dig 常用參數 與 DNS 偵錯追蹤
* DNS資源紀錄 (Resource Record) 介紹
* 10 Linux DIG Command Examples for DNS Lookup