Installing and Using dig in Ubuntu

Last Updated on: 

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 Linux, this command can be used to troubleshoot DNS problems.

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

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):

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:

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!

Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php