dig (domain information groper) is a network administration command-line tool for querying Domain Name System (DNS) servers. dig is useful for network troubleshooting and for educational purposes. dig can operate in interactive command line mode or in batch mode by reading requests from an operating system file.

When a specific name server is not specified in the command invocation, it will use the operating system’s default resolver, usually configured via the resolv.conf file. Without any arguments it queries the DNS root zone.

Make sure you read the dig manual here or on your Linux machine:

$ man dig

For start, let’s query Google’s DNS server for all A records that point to a specific DOMAIN:

$ dig A +additional +multiline +trace +dnssec <DOMAIN>. @8.8.4.4

For example, the output for nhs.uk should be similar to this:

$ dig +additional +multiline +trace +dnssec nhs.uk. @8.8.4.4

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.5 <<>> +additional +multiline +trace +dnssec nhs.uk. @8.8.4.4
;; global options: +cmd
.			174966 IN NS a.root-servers.net.
.			174966 IN NS b.root-servers.net.
.			174966 IN NS c.root-servers.net.
.			174966 IN NS d.root-servers.net.
.			174966 IN NS e.root-servers.net.
.			174966 IN NS f.root-servers.net.
.			174966 IN NS g.root-servers.net.
.			174966 IN NS h.root-servers.net.
.			174966 IN NS i.root-servers.net.
.			174966 IN NS j.root-servers.net.
.			174966 IN NS k.root-servers.net.
.			174966 IN NS l.root-servers.net.
.			174966 IN NS m.root-servers.net.
.			174966 IN RRSIG	NS 8 0 518400 20180224050000 (
				20180211040000 41824 .
				Y77nNi7hwrLAqwyo0u/5o4KYsBr1l3zy4p1vZmCki2hk
				3ASkbPn4pHBKxkaUkoeg76UX0/LAMxIP9DrP2zt++HUA
				7ergfnJeQXajKbXcy8h1ssqyT73dfykONhNHEG16t7hG
				DWNQIi+Ezfx9nCx0ewbSToFYR/U6Dl5B295NFFbj2eJC
				BxC2jM7urx0rg8nYS7ZQ0Ad/+y8gc9KG39yXdxVk1PUO
				1Xz3pSYkOfSdFZ3JP8WsY0k3vVXZRQL64T8fQNZqbklB
				WN+2okuK0zbepuWbJfd1w24hty/KkguTpMbFjR+hdQMx
				6qGpraG1mC1Vf5/67fjaiM0vHzxOW5vdvg== )
;; Received 525 bytes from 8.8.4.4#53(8.8.4.4) in 5 ms

uk.			172800 IN NS nsa.nic.uk.
uk.			172800 IN NS nsb.nic.uk.
uk.			172800 IN NS nsc.nic.uk.
uk.			172800 IN NS nsd.nic.uk.
uk.			172800 IN NS dns1.nic.uk.
uk.			172800 IN NS dns2.nic.uk.
uk.			172800 IN NS dns3.nic.uk.
uk.			172800 IN NS dns4.nic.uk.
uk.			86400 IN DS 43876 8 2 (
				A107ED2AC1BD14D924173BC7E827A1153582072394F9
				272BA37E2353BC659603 )
uk.			86400 IN RRSIG DS 8 1 86400 20180225210000 (
				20180212200000 41824 .
				Ug5UyBwuDYOuwclNyPq8oEzgXqnTsnrh6pol3R1EuZRr
				WGnfykz2AKEM4/TOIwglT52P249ZmpbKlXkG2b1eBB2J
				M2dlSPwvl2cAmR11vqbfIfoo1zVVbkM8ODegO2zTE3YK
				Y0wVlpNO0gsiZkklm/TrfL1IArCWx1xBlQDsBQAVRNNq
				1FgKsKlFZG+6RAzU5u0FFB4C1Cw196PC5z4zbeHN1n/8
				ViDwlhwebPGnRVi6YgCVnJmkf+HEVFiDFgFxUOPyjCrQ
				sO4pOToEWlyap5Yr9S7LveCSdfOIrmPRkHEatHRdSS5y
				ZS2N5RieeBjRk6dVN1l1dcjdSx5b1TTJmA== )
;; Received 790 bytes from 192.5.5.241#53(192.5.5.241) in 3 ms

nhs.uk.			172800 IN NS nsa.nhs.uk.
nhs.uk.			172800 IN NS nsb.nhs.uk.
u1fmklfv3rdcnamdc64sekgcdp05bbiu.uk. 10800 IN NSEC3 1 1 0 - U1LG7J6JO1NFSU55LON2UMGEUJO912TU NS SOA RRSIG DNSKEY NSEC3PARAM TYPE65534
u1fmklfv3rdcnamdc64sekgcdp05bbiu.uk. 10800 IN RRSIG NSEC3 8 2 10800 20180226231629 (
				20180212230027 43056 uk.
				0JG6hOI9yNytuuk70jwFR5EQ35AMkgMzRMK52Jui7e5a
				oNhBoFVqJpvyTS3sAgU/wnlrS7Qkr+U48jjyYqX5mgUD
				e+8ed5lu1hRsVH0oYbO6nMj/X4AoDC8Yyd7rn7vCR4w6
				dwR1MHa4v0PX83A9BimuMfZdUvBMnnlUurYhoR8= )
m20vtttlutai7b9rejotil7pg7vo7r9e.uk. 10800 IN NSEC3 1 1 0 - M222T760CFDGB7NJDNSC81FRVEQ2B9MR NS DS RRSIG
m20vtttlutai7b9rejotil7pg7vo7r9e.uk. 10800 IN RRSIG NSEC3 8 2 10800 20180226115640 (
				20180212105652 43056 uk.
				JEoeuG0z7mTanZuiixvliMNRyh7zhAnNWSHXbpAGSsJ2
				g+hdD0iKmwuZzcyZw9lsATRYjMzO3h/d/6fYoIJXp/vu
				up44CXZwUY5e6eQ4Gf7IqWlTtzHqLfWf5NtVVAt4LW2Q
				3VBk8zK09LsnrBBpIiNccg5B17AmRvM6tE9E3Ms= )
;; Received 620 bytes from 213.248.216.1#53(213.248.216.1) in 22 ms

nhs.uk.			300 IN A 94.245.104.73
;; Received 51 bytes from 194.176.105.223#53(194.176.105.223) in 90 ms

If you don’t need all the trace info, you can remove the +trace option:

$ dig +additional +multiline +dnssec nhs.uk. @8.8.4.4

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.5 <<>> +additional +multiline +dnssec nhs.uk. @8.8.4.4
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52096
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags: do; udp: 512
;; QUESTION SECTION:
;nhs.uk.			IN A

;; ANSWER SECTION:
nhs.uk.			299 IN A 94.245.104.73

;; Query time: 116 msec
;; SERVER: 8.8.4.4#53(8.8.4.4)
;; WHEN: Tue Feb 13 04:21:53 2018
;; MSG SIZE  rcvd: 51

You can get the shortest output by specifying several parameters to dig:

$ dig NS +noadditional +noquestion +nocomments +nocmd +nostats +multiline +dnssec nhs.uk. @8.8.4.4

nhs.uk.			21598 IN NS nsa.nhs.uk.
nhs.uk.			21598 IN NS nsb.nhs.uk.

Retriving all data for a domain name from a DNS server is easy, just query for ANY record:

$ dig ANY +noadditional +noquestion +nocomments +nocmd +nostats +multiline +dnssec nhs.uk. @8.8.4.4

nhs.uk.			21599 IN SOA external.nhs.uk. hostmaster.nhs.uk. (
				2018021205 ; serial
				86400      ; refresh (1 day)
				3600       ; retry (1 hour)
				604800     ; expire (1 week)
				86400      ; minimum (1 day)
				)
nhs.uk.			59 IN TXT "b784b596b64445748bdbfa14e7ab7f40"
nhs.uk.			59 IN TXT "facebook-domain-verification=lv7tnthk77oqcuocg7u86rnoafjj3z"
nhs.uk.			59 IN TXT "v=spf1 ip4:213.161.89.71 ip4:213.161.89.72 ip4:213.161.89.73 ip4:213.161.89.103 ip4:213.161.89.104 ip4:213.161.89.105 -all"
nhs.uk.			21599 IN NS nsb.nhs.uk.
nhs.uk.			21599 IN NS nsa.nhs.uk.
nhs.uk.			21599 IN MX 50 mail.nhs.uk.
nhs.uk.			299 IN A 94.245.104.73

Of course, you can query the DNS servers for any type of records, A, AAAA, PTR, CNAME, MX, NS, SOA, TXT and so on.

Some public DNS servers you can query are below: