media file explorer download upload index folder image licenses menu widget Play Pause profile-settings more dots-two-horizontal dots-two-vertical more-vertical pending google-plus hangouts facebook instagram whatsapp spotify telegram twitter vine renren rss youtube twitch vimeo flickr dribble behance deviantart 500px steam github soundcloud skype reddit linkedin lastfm delicious stackoverflow pinterest xing flattr foursquare yelp World

Installing and Using dig in Ubuntu

dig is an awesome utility for querying DNS name servers. It performs DNS lookups and
displays the answers that are returned from the name server(s) that were queried.

In this guide, you'll learn how to install and use dig in GNU/Linux, this command can be used to troubleshoot DNS problems.

To install dig in Ubuntu, you simply use the following command:

sudo apt install dnsutils

Verify the dig installation by running dig -v

To query a domain name, you use the following command (I would be using devsrealm as an example):

dig devsrealm.com

Output:

; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> devsrealm.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25063
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;devsrealm.com.                 IN      A

;; ANSWER SECTION:
devsrealm.com.          299     IN      A       89.50.54.86

;; Query time: 870 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Thu Jul 02 19:04:15 UTC 2020
;; MSG SIZE  rcvd: 58

You can see it returned the result, to get only the IP of the domain you are querying, you can use:

dig devsrealm.com +short

The above would only return the IP of the domain.

Checking MX record of a domain

user@server:~$ dig devsrealm.com MX +short

10 mxa.mailgun.org.
10 mxb.mailgun.org.

Checking Name Server of a Domain

user@server:~$ dig devsrealm.com NS +short
ns1.devsrealm.com.
ns2.devsrealm.com.

Checking TXT of a Domain

user@server:~$ dig devsrealm.com TXT +short
"v=spf1 a mx ip4:89.50.54.86 ~all"
"v=spf1 include:mailgun.org ~all"

You can read more using the man page, it can really be a lifesaver if you are troubleshooting DNS related problem.

Enjoy!