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...]
To get you ip adress, using the server resolver1.opendns.com:
dig @resolver1.opendns.com ANY myip.opendns.com +short
Get the address for bigg.blog
dig bigg.blog A +noall +answer
Command to get a list of the mailservers for bigg.blog
dig bigg.blog MX +noall +answer
The following command is to get a list of authoritative DNS servers for bigg.blog
dig bigg.blog NS +noall +answer
To get a list of all the above (MX and NS) at once
dig bigg.blog ANY +noall +answer
Trace the path taken to resolve the name
dig bigg.blog +trace
dig +answer -x 126.96.36.199
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