Friday, January 22, 2016

dig Examples


Below are a couple of examples on how you can use dig. These are common examples and include queries such as mail exchange lookup, address record lookup, reverse dns lookup, etc.
you can always add the  '+short' option at the end of any dig command to keep the output manageable:

eg dig www.example.com +short

Perform a Basic DNS Dig
This is simply going to tell us what the IP address is for the domain www.example.com. The output will be an IP address which will be something like 1.2.3.4.

dig www.example.com

Reverse DNS Dig
Perform a reverse DNS dig lookup. This will translate an IP address into its domain name. The output will be a domain name such as www.example.com.

dig -x 1.2.3.4

Dig MX Record Lookup
An MX (Mail Exchange) record tells us that the record is a domain name that is responsible for accepting email. The below command will tell us what domain name the mail record below is pointing as well as the priority of the mail records. . The output will be the domain name the record points to such as mail.example.com, which tells us that the mx record example.com resolves to mail.example.com.

dig -t MX example.com

Show the TXT or SPF records

dig example.com txt

Directly Query A DNS Server
By default the dns query will resolve off of your own dns server (which is usually the dns server of your ISP or local server), however we can manually specify the dns server we want to query by adding @ns1.example.com to the dns dig command.


dig @ns1.example.com www.somedomain.com

Directly Query the TXT records of a  specific name server
dig @ns1.example.com www.somedomain.com txt

Show the Name servers of a domain
Here's how to query for a list of nameservers for a given domain,

dig example.com ns

dig traceroute information
If you like the traceroute command, you can do something similar with dig to follow DNS nameservers, like this, using the

dig example.com  +trace

 or to keep the output manageable:

dig example.com  +trace +short







No comments: