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!

7 Answers 7

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.

6
  • Thats what i thought too but its only showing me the reverse dns arpa zones
    – DuPie
    Jun 21, 2012 at 18:22
  • I would check the log files for more information. If only the reverse ARPA zones are in the dump file, I would say that only these are loaded in the DNS server. Jun 21, 2012 at 18:25
  • 1
    Where is BIND's data directory?
    – Qian Chen
    Jul 15, 2016 at 19:16
  • 2
    On Debian jessie the file ended in /var/cache/bind/named_dump.db
    – Calimo
    Nov 15, 2016 at 12:21
  • 1
    It is in /var/named/data in centos 7
    – Bhargav
    Jul 25, 2020 at 0:31
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
2
  • Looks like the -l option has went away by v9.16.22. Feb 1, 2022 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) <id:2b2afb2> 387
    – robbat2
    May 21, 2023 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.

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.

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
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
2
  • 2
    please explain more.
    – Sven
    Jan 13, 2016 at 9:07
  • Please refer the edited answer. Jan 27, 2016 at 4:28
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.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .