Useful examples of dig command

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 resolver1.opendns.com:
dig @resolver1.opendns.com ANY myip.opendns.com +shortGet the address for bigg.blog
dig bigg.blog A +noall +answerCommand to get a list of the mailservers for bigg.blog
dig bigg.blog MX +noall +answerThe following command is to get a list of authoritative DNS servers for bigg.blog
dig bigg.blog NS +noall +answerTo get a list of all the above (MX and NS) at once
dig bigg.blog ANY +noall +answerTrace the path taken to resolve the name
dig bigg.blog +traceReverse lookup
dig +answer -x 104.24.116.215Query names from a file
dig -f domain_list.txt +shortTo customise permanently the output, you need to create a file ~/.digrc like
echo "+noall +answer" > ~/.digrcNow, when dig is executed it will show only answer section will output.
Hope it helps you
Have a great day
G