List all DNS records in a domain using dig?

My company runs an internal DNS for mycompany.example

There is a machine on the network that I need to find, but I’ve forgotten its name. If I could see a list, it would probably jog my memory.

How can I list all of the domain records for mycompany.example?


Answer

The short answer to your specific question of listing CNAMEs is that you cannot without permission to do zone transfers (see How to list all CNAME records for a given domain?).

That said, if your company's DNS server still supports the ANY query, you can use dig to list the other records by doing:

dig +noall +answer +multiline yourdomain.yourtld any 

These ... +noall +answer +multiline ... are strictly optional and are simply output formatting flags to make the output more easily human readable (see dig man page ).

Example

$ dig +noall +answer +multiline bad.horse any

Returns:

bad.horse.              7200 IN A 162.252.205.157
bad.horse.              7200 IN CAA 0 issue "letsencrypt.org"
bad.horse.              7200 IN CAA 0 iodef "mailto:[email protected]"
bad.horse.              7200 IN MX 10 mx.sandwich.net.
bad.horse.              7200 IN NS a.sn1.us.
bad.horse.              7200 IN NS b.sn1.us.
bad.horse.              7200 IN SOA a.sn1.us. n.sn1.us. (
                                2017032202 ; serial
                                1200       ; refresh (20 minutes)
                                180        ; retry (3 minutes)
                                1209600    ; expire (2 weeks)
                                60         ; minimum (1 minute)
                                )

Caveats (RFC8482)

Note that, since around 2019, most public DNS servers have stopped answering most DNS ANY queries usefully. For background on that, see: https://blog.cloudflare.com/rfc8482-saying-goodbye-to-any/

If ANY queries do not enumerate multiple records, the only option is to request each record type (e.g. A, CNAME, or MX) individually.


A much easier command to remember (and more informative) is:

> dig google.com ANY

Which returns the following:

; <<>> DiG 9.8.3-P1 <<>> google.com ANY
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31013
;; flags: qr rd ra; QUERY: 1, ANSWER: 22, AUTHORITY: 0, ADDITIONAL: 3

;; QUESTION SECTION:
;google.com.            IN  ANY

;; ANSWER SECTION:
google.com.     17  IN  A   74.125.225.72
google.com.     17  IN  A   74.125.225.73
google.com.     17  IN  A   74.125.225.78
google.com.     17  IN  A   74.125.225.64
google.com.     17  IN  A   74.125.225.65
google.com.     17  IN  A   74.125.225.66
google.com.     17  IN  A   74.125.225.67
google.com.     17  IN  A   74.125.225.68
google.com.     17  IN  A   74.125.225.69
google.com.     17  IN  A   74.125.225.70
google.com.     17  IN  A   74.125.225.71
google.com.     86400   IN  NS  ns1.google.com.
google.com.     86400   IN  NS  ns2.google.com.
google.com.     86400   IN  NS  ns3.google.com.
google.com.     86400   IN  NS  ns4.google.com.
google.com.     66641   IN  SOA ns1.google.com. dns-admin.google.com.    2013082900 7200 1800 1209600 300
google.com.     177 IN  MX  40 alt3.aspmx.l.google.com.
google.com.     177 IN  MX  50 alt4.aspmx.l.google.com.
google.com.     177 IN  MX  10 aspmx.l.google.com.
google.com.     177 IN  MX  20 alt1.aspmx.l.google.com.
google.com.     177 IN  MX  30 alt2.aspmx.l.google.com.
google.com.     287 IN  AAAA    2607:f8b0:4009:803::1007

;; ADDITIONAL SECTION:
ns1.google.com.     3924    IN  A   216.239.32.10
ns2.google.com.     64508   IN  A   216.239.34.10
ns3.google.com.     64508   IN  A   216.239.36.10

;; Query time: 77 msec
;; SERVER: 10.6.23.4#53(10.6.23.4)
;; WHEN: Fri Sep 13 14:26:09 2013
;; MSG SIZE  rcvd: 506