Saturday 27 February 2021

Dig Basic Commands in Linux

The dig (Domain Information Groper) is a very useful utilities for querying DNS name servers. 

List of useful dig commands.

To check dig version

# dig -v

 

To get help page

# dig -h

 

To query a single host (domain) without any additional options

# dig gitlab.com

 

To get a short answer to your query

 # dig gitlab.com +short

 

To turn off all the results and then turn on only the answer section 

 # dig gitlab.com +noall  +answer

 

To specify a name server ( By default use /etc/resolv.conf file if no name server is specified)

  # dig gitlab.com @8.8.8.8

 

To query based on record type ( any, a , cname, txt, mx and ns record )

# dig +nocmd gitlab.com any +noall +answer

# dig +nocmd gitlab.com a +noall +answer

#dig +nocmd gitlab.com cname +noall +answer

#dig +nocmd gitlab.com txt +noall +answer

#dig +nocmd gitlab.com mx +noall +answer

#dig +nocmd gitlab.com ns +noall +answer

 

 To query reverse lookup

#dig -x 95.216.246.23 +noall +answer

 

To query a large number of domains ( i.e from a file )

#dig -f test.txt +short