The dig command is a tool for querying Domain Name System (DNS) name servers. With no flags dig returns the A record for a domain if it exists. To dig for other records simply pass the record type in the command:
For nameservers use the ns flag
dig example.com ns
For mx records use the mx flag
dig example.com mx
For txt/spf records use the txt flag
dig example.com txt
Dig against a specified nameserver
dig example.com @ns1.mynameserver.com
Only return the results without all the other information by passing the +short parameter
dig example.com +short
Use the +trace parameter to make iterative queries to resolve the name being looked up. It will follow referrals from the root servers, showing the answer from each server that was used to resolve the lookup. This is handy when trying to figure out why a domain may not be resolving
[gitlab] (~) >>> dig +trace example.com
; <<>> DiG 9.8.1-P1 <<>> +trace example.com
;; global options: +cmd
. 257 IN NS g.root-servers.net.
. 257 IN NS b.root-servers.net.
. 257 IN NS k.root-servers.net.
. 257 IN NS e.root-servers.net.
. 257 IN NS d.root-servers.net.
. 257 IN NS a.root-servers.net.
. 257 IN NS l.root-servers.net.
. 257 IN NS j.root-servers.net.
. 257 IN NS i.root-servers.net.
. 257 IN NS h.root-servers.net.
. 257 IN NS f.root-servers.net.
. 257 IN NS c.root-servers.net.
. 257 IN NS m.root-servers.net.
;; Received 228 bytes from 10.0.80.11#53(10.0.80.11) in 4 ms
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
;; Received 489 bytes from 193.0.14.129#53(193.0.14.129) in 33 ms
example.com. 172800 IN NS a.iana-servers.net.
example.com. 172800 IN NS b.iana-servers.net.
;; Received 165 bytes from 192.33.14.30#53(192.33.14.30) in 238 ms
example.com. 86400 IN A 93.184.216.119
example.com. 172800 IN NS a.iana-servers.net.
example.com. 172800 IN NS b.iana-servers.net.
;; Received 93 bytes from 199.43.132.53#53(199.43.132.53) in 21 ms
To dig all records for a domain you can use some additional flags as show below.
[gitlab] (~) >>> dig +nocmd google.com any +multiline +noall +answer
google.com. 2941 IN TXT "v=spf1 include:_spf.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all"
google.com. 78 IN A 74.125.227.131
google.com. 78 IN A 74.125.227.142
google.com. 78 IN A 74.125.227.135
google.com. 78 IN A 74.125.227.129
google.com. 78 IN A 74.125.227.132
google.com. 78 IN A 74.125.227.133
google.com. 78 IN A 74.125.227.130
google.com. 78 IN A 74.125.227.134
google.com. 78 IN A 74.125.227.137
google.com. 78 IN A 74.125.227.136
google.com. 78 IN A 74.125.227.128
google.com. 131 IN NS ns1.google.com.
google.com. 131 IN NS ns3.google.com.
google.com. 131 IN NS ns4.google.com.
google.com. 131 IN NS ns2.google.com.