Useful examples of dig command

Useful examples of dig command

linux recipe dig command dns resolve

This recipe is about the dig command in Unix and some useful examples, which you can find interesting when scripting or when need to check your address from inside the machine that you are accessing by the private network.

dig is an acronym for Domain Information Groper and is a command-line utility that performs DNS lookup by querying name servers and displaying the result to you. It is part of the dnsutils package in Debian, make sure you have that installed.

The syntax is:

dig [@server] [-b address] [-c class] [-f filename] [-k filename] [-m] [-p port#] [-q name] [-t type] [-x addr] [-y [hmac:]name:key] [-4] [-6] [name] [type] [class] [queryopt...] 

Some examples:

To get you ip adress, using the server

dig ANY +short

Get the address for

dig A +noall +answer

Command to get a list of the mailservers for

dig MX +noall +answer

The following command is to get a list of authoritative DNS servers for

dig NS +noall +answer

To get a list of all the above (MX and NS) at once

dig ANY +noall +answer 

Trace the path taken to resolve the name

dig +trace

Reverse lookup

dig +answer -x

Query names from a file

dig -f domain_list.txt +short

To customise permanently the output, you need to create a file ~/.digrc like

echo "+noall +answer" > ~/.digrc

Now, when dig is executed it will show only answer section will output.

Hope it helps you
Have a great day


Hope you find this useful, if you have any question please visit my twitter @bigg_blog and if you have a couple of pounds make a donation .

Add a comment

Previous Post Next Post