dig command stands for Domain Information Groper. It is used for retrieving information about DNS name servers. It is basically used by network administrators. It is used for verifying and troubleshooting DNS problems and to perform DNS lookups. Dig command replaces older tools such as nslookup and the host.
Installing Dig command
In case of Debian/Ubuntu
$sudo apt-get install dnsutils
In case of CentOS/RedHat
$sudo yum install bind-utils
Syntax:
dig [server] [name] [type]
Working with Dig Command
1. To query domain “A” record
dig geeksforgeeks.org
A record refers to IPV4 IP.
Similarly, if record type is set as “AAAA”, this would return IPV6 IP.
2. To query domain “A” record with +short
dig geeksforgeeks.org +short
dig geeksforgeeks.org +nocomments
dig geeksforgeeks.org +noall
dig geeksforgeeks.org +noall +answer
dig geeksforgeeks.org ANY
dig geeksforgeeks.org MX
dig geeksforgeeks.org +trace
dig geeksforgeeks.org @8.8.8.8
dig geeksforgeeks.org +noall +answer +stats
Reverse DNS Lookup:
Reverse DNS lookup can be used to fetch domain name or the host name from the IP address.
“-x” option is used to perform reverse DNS lookup.
ex:
[xxxxxx ~]# dig +noall +answer -x 8.8.8.8
8.8.8.8.in-addr.arpa. 18208 IN PTR dns.google.
Note: DNS reverse look up will work only if the entry is present PTR.
PTR contents can be viewed using the command “dig -x xx.yy.zz.aa”
Batch Queries:
Instead performing dig query for each domain at a time, a list of domains can be queried at once.
To do so, enter the domain names in a file, only 1 domain name in each line and perform the dig query on file.
ex: let’s say, file.txt has the list of domain names to be queried then,
dig -f file.txt +shortwill perform DNS queries and return all the resolved IPs.