18

I'm trying to migrate a dns server that has several thousand zones loaded on it. The named.conf file has about 17 different includes, and some of those files also has includes in them, and lots of commented out etc. It's a fricking mess!

I'm wanting to get a list of all the zones currently loaded into BIND. I looked at rndc dumpdb but it doesn't show me just the zones.

Instead of following the messy include files, is there an easier way to get a list of the authorative zones inside BIND? Thanks!

DuPie
  • 418
  • 1
  • 4
  • 11

7 Answers7

21

You can run rndc dumpdb -zones to create a file called cache_dump.db. This file will contain all authoritative zones and will be created in BIND's data directory.

Vladimir Blaskov
  • 6,183
  • 1
  • 27
  • 22
5

For newer versions of BIND9, as of 9.12.0a1; there also named-checkconf -l that can list the zones in an easy format, including master/slave status and views.

Example:

$ sudo /usr/sbin/named-checkconf -l -t /chroot/bind/
example.com IN external master
otherdomain.com IN external slave
internal.example.com IN internal master
example.com IN internal in-view external
otherdomain.com IN internal in-view external

# this has 2 views: external, internal
# and 3 zones: example.com, otherdomain.com, internal.example.com
# the external view contains: example.com, and slaves otherdomain.com
# the internal view uses in-view statements to show
# the same version of external zones, plus contains a unique zone
robbat2
  • 350
  • 5
  • 10
  • Looks like the `-l` option has went away by v9.16.22. – John Greene Feb 01 '22 at 18:46
  • 1
    @JohnGreene still seems to work in v9.16.37: ```named -V |head -n1 ; named-checkconf -l -t /chroot/dns |wc -l BIND 9.16.37 (Extended Support Version) 387``` – robbat2 May 21 '23 at 19:11
3

Confirmed rndc dumpdb is the best method.

In my case, i discovered that there was 2 seperate bind instances running on the same server (don't ask), one doing forward dns and one doing reverse dns. Without specifying the PID, it attached to the one only doing reverse dns and only showed me that.

DuPie
  • 418
  • 1
  • 4
  • 11
2

If you just want to have the configuration (including any include files) printed in its canonical form, you could simply call:

named-checkconf -p (optionally with -t /some/chroot/dir if BIND runs chrooted and the config needs to be read from the chroot dir)

This flattens out all the include files, removes all comments and formats everything neatly.

While the output will include statically configured zones, it will not list dynamic zones, like those added with rndc addzone.

Jim Class
  • 23
  • 4
Håkan Lindqvist
  • 35,011
  • 5
  • 69
  • 94
1

Adding -all does the trick for me (on Ubuntu Ubuntu 16.04.2 LTS (xenial))

sudo rndc dumpdb -all && cat /var/cache/bind/named_dump.db
Pfiver
  • 111
  • 1
0

The following is the exact command to list the zones that are loaded during startup. This is tested on RHEL6.7 x86_64.

/usr/sbin/named-checkconf -z -t /var/named/chroot | grep loaded

Example:

[root@dnsserver ~]# /usr/sbin/named-checkconf -z -t /var/named/chroot | grep loaded
zone 0.0.127.in-addr.arpa/IN: loaded serial 2008040700
zone 19.58.10.in-addr.arpa/IN: loaded serial 2008040701
zone 11.54.10.in-addr.arpa/IN: loaded serial 2008040700
zone example.com/IN: loaded serial 2008040702
zone ./IN: loaded serial 2008040700
0

Another alternative is to use bind's own XML format statistics, if you have enabled the statistics-channel and have zone-statistics enabled (e.g. in the global options { }). This method also lets you easily select/show views, zone types and zone data (e.g. serial number), as well as statistics per-zone of course.

Using wget and xml (xmlstarlet):

wget -O - http://127.0.0.1:1080/xml/v3/zones | 
  xml select -I -t -m '/statistics/views/view[@name="_default"]/zones/zone[type="master"]' \
    -v @name -nl

The above shows a list of all master domains in the _default view.

wget ... |
  xml select -I -t -m '/statistics/views/view/zones/zone' \
   -v @name -o , -v ../../@name -o , -v type -o , -v serial -nl

The above shows all zones in CSV form: zone, view, type, serial.

To select only a specific view and zone type:

 wget ... |
   xml select -I -t -m '/statistics/views/view[@name="_bind"]/zones/zone[type="builtin"]' \
     -v @name -nl

(This statistics facility is available since bind-9.6.0, December 2008. The /v3/ format used above is only available since bind-9.10, April 2014. JSON format may also be available, so something analogous should be possible with jot.)

mr.spuratic
  • 3,430
  • 20
  • 14