Dig Command Examples

Simple Dig Command

[[email protected] ~]# dig justgeek.net

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> justgeek.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53092
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;justgeek.net.                  IN      A

;; ANSWER SECTION:
justgeek.net.           267     IN      A       104.28.12.34
justgeek.net.           267     IN      A       104.28.13.34
justgeek.net.           267     IN      A       172.67.130.28

;; Query time: 10 msec
;; SERVER: 108.61.10.10#53(108.61.10.10)
;; WHEN: Wed May 27 07:13:17 UTC 2020
;; MSG SIZE  rcvd: 89

How to check A record of the website using DIG command

[[email protected] ~]# dig redhat.com +noall +answer

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> redhat.com +noall +answer
;; global options: +cmd
redhat.com. 3547 IN A 209.132.183.105

Check MX record using dig command

[[email protected] ~]# dig redhat.com MX +noall +answer

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> redhat.com MX +noall +answer
;; global options: +cmd
redhat.com. 600 IN MX 10 us-smtp-inbound-2.mimecast.com.
redhat.com. 600 IN MX 10 us-smtp-inbound-1.mimecast.com.
[[email protected] ~]#

How to check NS record of the website using DIG command.

[[email protected] ~]# dig justgeek.net NS +noall +answer

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> justgeek.net NS +noall +answer
;; global options: +cmd
justgeek.net. 86400 IN NS kia.ns.cloudflare.com.
justgeek.net. 86400 IN NS jerome.ns.cloudflare.com.
[[email protected] ~]#

About nslookup

So here we wil learn about NSLOOKUP (Name Server Lookup) and we will see some of it’s examples.

So we will start with, What is nslookup

nslookup is the tool which lets you the enter the host-name or domain name and see it’s corresponding IP address. It also lets you to pass IP address and get corresponding hostname. (reverse DNS)

Installation, if your CentOS machine says nslookup command not found.

[[email protected] /]# nslookup google.com
-bash: nslookup: command not found

so here you will have to Install bind-utils to get nslookup command. Simply run yum install bind-utils to take advantage of nslookup command.

[[email protected] /]# yum install bind-utils

nslookup command examples.

nslookup command followed by domain/hostname will display IP address of the domain.

[[email protected] /]# nslookup unix.com
Server:         108.61.10.10
Address:        108.61.10.10#53
 
Non-authoritative answer:
Name:   unix.com
Address: 209.126.104.117

You can use -type option to get various dns details. For example to get MX records.

[[email protected] /]# nslookup -type=mx redhat.com
Server:         108.61.10.10
Address:        108.61.10.10#53

Non-authoritative answer:
redhat.com      mail exchanger = 10 us-smtp-inbound-2.mimecast.com.
redhat.com      mail exchanger = 10 us-smtp-inbound-1.mimecast.com.

To get nameserver of the domain.

[[email protected] /]# nslookup -type=ns google.com
Server:         108.61.10.10
Address:        108.61.10.10#53

Non-authoritative answer:
google.com      nameserver = ns3.google.com.
google.com      nameserver = ns2.google.com.
google.com      nameserver = ns1.google.com.
google.com      nameserver = ns4.google.com.

Reverse DNS

[[email protected] /]#  nslookup 209.132.183.181
181.183.132.209.in-addr.arpa    name = origin-www2.redhat.com.

Authoritative answers can be found from:

To get Information using specific DNS server.

[[email protected] /]# nslookup redhat.com ns1.redhat.com
Server:         ns1.redhat.com
Address:        209.132.186.218#53

Name:   redhat.com
Address: 209.132.183.105

we have used the ns1.redhat.com as the DNS server. Here you may notice that, we don’t get any “Non-authoritative answer:” header, since ns1.redhat.com has all the zone information of redhat.com