The dig utility

dig (domain information groper) — utility (DNS client) for working with domain records. Used to query DNS servers and obtain records for requested domain.

  • +short — short answer (without request and service information).
  • +noall +answer — detailed answer (no request).
  • @server — query to specific DNS server.
  • record — to get information about a specific record, just specify its name.
  • -x IP address — reverse DNS lookup.
  • +trace — domain query route trace.
  • -f path/to/file — query information for multiple domains at once, listed in file.

Frequently used options can be set by default.

The simplest query:

dig hosting.xyz

Answer with explanatory comments:

; <<>> DiG 9.11.3-1ubuntu1.9-Ubuntu <<>> hosting.xyz       # dig version and query text
;; global options: +cmd                                       # global parameters
;; Got answer:                                                # technical details about received answer
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25243     # header including operation code and action status
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1452
;; QUESTION SECTION:                                          # query section
;hosting.xyz.                        IN      A             # by default, an A record is requested

;; ANSWER SECTION:                                            # answer section
hosting.xyz.         900     IN      A       185.39.224.54 # IP address for A record

;; Query time: 17 msec                                        # query statistics
;; SERVER: 1.1.1.1#53(1.1.1.1)                                # address of server that returned response
;; WHEN: Thu Oct 24 14:45:14 EEST 2019                        # date and time
;; MSG SIZE  rcvd: 59

To get a short answer, use +short:

dig hosting.xyz +short

Answer:

185.39.224.54

To get only the answer section, use +noall (disables all results) and +answer (enables answer section):

dig hosting.xyz +noall +answer

Answer:

; <<>> DiG 9.11.3-1ubuntu1.9-Ubuntu <<>> hosting.xyz +noall +answer
;; global options: +cmd
hosting.xyz.         734     IN      A       185.39.224.54

To get a response from a specific DNS server, use @server option (server is name or IP of specific DNS server):

dig hosting.xyz @8.8.8.8

Answer:

; <<>> DiG 9.11.3-1ubuntu1.9-Ubuntu <<>> hosting.xyz @8.8.8.8
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14828
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;hosting.xyz.                        IN      A

;; ANSWER SECTION:
hosting.xyz.         608     IN      A       185.39.224.54

;; Query time: 26 msec
;; SERVER: 8.8.8.8#53(8.8.8.8) # here you can see that the response was returned by the server specified in the command
;; WHEN: Thu Oct 24 15:05:58 EEST 2019
;; MSG SIZE  rcvd: 59

Query information about a specific entry

To get information about a specific record, add its name (A, AAAA, CNAME, TXT, MX, NS):

dig hosting.xyz mx +noall +answer

Answer:

; <<>> DiG 9.11.3-1ubuntu1.9-Ubuntu <<>> hosting.xyz mx +noall +answer
;; global options: +cmd
hosting.xyz.         900     IN      MX      20 alt1.aspmx.l.google.com.
hosting.xyz.         900     IN      MX      10 aspmx.l.google.com.

To determine hostname by IP address (PTR record), use -x key:

dig -x 185.39.224.54 +noall +answer

Answer:

; <<>> DiG 9.11.3-1ubuntu1.9-Ubuntu <<>> -x 185.39.224.54 +noall +answer
;; global options: +cmd
54.224.39.185.in-addr.arpa. 3250 IN     PTR     hosting.xyz.
When tracing, try to use the +nodnssec key to avoid cluttering output with information unnecessary for your case.

To view detailed information about request processing and determine which server at which stage returned which response, use +trace option:

dig hosting.xyz a +trace

Answer:

; <<>> DiG 9.11.3-1ubuntu1.9-Ubuntu <<>> ukraine.com.ua a +trace
;; global options: +cmd
.                       6839    IN      NS      h.root-servers.net.
.                       6839    IN      NS      i.root-servers.net.
.                       6839    IN      NS      j.root-servers.net.
.                       6839    IN      NS      k.root-servers.net.
.                       6839    IN      NS      l.root-servers.net.
.                       6839    IN      NS      m.root-servers.net.
.                       6839    IN      NS      a.root-servers.net.
.                       6839    IN      NS      b.root-servers.net.
.                       6839    IN      NS      c.root-servers.net.
.                       6839    IN      NS      d.root-servers.net.
.                       6839    IN      NS      e.root-servers.net.
.                       6839    IN      NS      f.root-servers.net.
.                       6839    IN      NS      g.root-servers.net.
.                       6839    IN      RRSIG   NS 8 0 518400 20191106050000 20191024040000 22545 . VMJm6mjyJGRlIHIZFqe63o28rV9XrZpMEOjhFIW094xMFd7s2LL49Dfq +gaiZ549QmIfHUNnTAg9ZGeNHgxs+AFobw5/4ag6oieqo6wJdnwLEIcr AdMeHFz6UJ6FA5MKGWTTY/oBfdfCujbCgTxeMKK1sBwrBLrZ70yfH57x 9/tjVsAYagE5sEi+leATrOtBtJf1FfJqa9wD1ps5GAiOODtI7E+FDFsI 6ZvnTqp0d4qnIcNhf1UiUyvhYoFo7OqnJjDo15h/JMMfG1/9Ope1lAba 9Cdg+ufcIpbfIn63ppq6t/gFGsNUO/+E0rTDno2PdKu0w4rmVxN9ouY/ Hs1/Rw==
;; Received 717 bytes from 1.1.1.1#53(1.1.1.1) in 17 ms                  # current DNS server (1.1.1.1) returned root zone . NS list

ua.                     172800  IN      NS      in1.ns.ua.
ua.                     172800  IN      NS      sns-pb.isc.org.
ua.                     172800  IN      NS      pch.ns.ua.
ua.                     172800  IN      NS      ho1.ns.ua.
ua.                     172800  IN      NS      cd1.ns.ua.
ua.                     86400   IN      DS      56514 10 2 BDD7A310534F76B2B6B25C94F816F9B9F260A2E35F526A9287E3307F B2CD16D8
ua.                     86400   IN      RRSIG   DS 8 1 86400 20191106050000 20191024040000 22545 . PHQOb4/tp5HtTwtiQ0IebMKNLAoI1GII/AWckr7t05TyiwBIgby7LAQL xXAUwHDtVA3I7CFtAD+0Oma07ncWBcs3j4L5zFm69R4vZO0nd7uiBty9 hdyM6HssNMujDfmxKIT7LSkVqKOtA9RELwibjjpU5oao8ZpQr8l8e4JQ wK+5A4A14ZZXUk6MFeG9P0QtWOdfBfnq+Ei8DfHCrmG1KpHQVE9F96Fm ItP5GEh7Upx7sV6CvnLYYYTvlwGZyI6eYIaEOW6hhufp2Gs7rSvfKpI3 /CUYZeO9ZstXxowgQno9qShAzSO2nOdfRF6GMVWIrfRr3q7ov8jFxGUO 7a+PsA==
;; Received 729 bytes from 192.112.36.4#53(g.root-servers.net) in 43 ms  # a list of NS records for .UA zone was received from one of root zone servers

com.ua.                 36036   IN      NS      k.ns.com.ua.
com.ua.                 36036   IN      NS      ba1.ns.ua.
com.ua.                 36036   IN      NS      ho1.ns.com.ua.
com.ua.                 36036   IN      NS      nix.ns.ua.
com.ua.                 36036   IN      NS      sns-pb.isc.org.
com.ua.                 36036   IN      DS      51391 13 2 0B165D1C0B8481335BF9AA08B6D4A989FAA387E50CB20012B9679FDA C8DCC523
com.ua.                 36036   IN      RRSIG   DS 10 2 36036 20191123103100 20191024103100 39635 ua. kTcOwmqs1zfsgT3/EN/98p4FtRBgziggjAAK2tVm3jo+rpzKu213c9s5 jC17CrEULnG5sNry8SVrf8VpfIho89eb9D0+waSu9QTtjOjhuO/JIYJf 1HCkAug3GUcg+Fhspaasam07yadA+rjhBoLo1PSzIJatP5nSo3CRdQBv sFw=
;; Received 1181 bytes from 74.123.224.40#53(in1.ns.ua) in 180 ms        # NS list for .COM.UA zone received from .UA zone server

ukraine.com.ua.         28800   IN      NS      ns1.ukraine.com.ua.
ukraine.com.ua.         28800   IN      NS      ns2.ukraine.com.ua.
ukraine.com.ua.         28800   IN      NS      ns3.ukraine.com.ua.
TQ2PJLFLEH6Q350I1RFS6O2279S9UJ6F.com.ua. 1800 IN NSEC3 1 1 10 08FA761AF54F7014 TQ3G5M4AQH5FQAAES9MGMV6PMBPK9APC  NS SOA RRSIG DNSKEY NSEC3PARAM
TQ2PJLFLEH6Q350I1RFS6O2279S9UJ6F.com.ua. 1800 IN RRSIG NSEC3 13 3 1800 20191208104006 20191024104006 60182 com.ua. d+EcdzD+RIlQW3zgYKy3DdDu/fTH9BXbLphzBc0uehoTCHvkyaQhjF85 EJ7xjqqJ59Y7tHfbuVegW4Zoff+kvA==
3L3FI89Q3TEFK874E9180CD71K7GJ6QA.com.ua. 1800 IN NSEC3 1 1 10 08FA761AF54F7014 3L58G1AMG8IQ3NECEU3AD9LA8E8BR3I6  TXT RRSIG
3L3FI89Q3TEFK874E9180CD71K7GJ6QA.com.ua. 1800 IN RRSIG NSEC3 13 3 1800 20191208104006 20191024104006 60182 com.ua. xB5O1l8/ZgMUUdo5VxXO9PkFL43TBDktY9p0pphZscFkTs3XZTdb+h6e gDUpqSxPaVqPv4FczT/f4yOF5CNegA==
;; Received 608 bytes from 216.218.215.123#53(k.ns.com.ua) in 182 ms     # received NS domain list from .COM.UA zone server

ukraine.com.ua.         900     IN      A       185.39.224.54
;; Received 59 bytes from 91.222.136.245#53(ns2.ukraine.com.ua) in 13 ms # one of domain NS returned information about A record

To get a response for multiple domains at once, create a plain text file with a list of domains (each domain on a new line) and specify key -f and path to file with domains in command instead of domain:

dig -f domains.txt MX +short

When you frequently use the same options, to avoid entering them manually each time, you can create text file .digrc in user root directory and place them there in one line:

+noall +answer

As a result, each time you run dig, these options will be automatically added to the query.

Content

    (1)