3

Now that I'm moving my main server, I'm spending some time refining and simplifying some of its setup, and it has now come to the DNS server (bind 9.9.5 in the new setup).

I noticed that in my config, I have a lot of zones defined this way:

zone "123.123.123.123.in-addr.arpa" in {
        type master;
        file "123.123.123.123";
};

zone "123.123.123.124.in-addr.arpa" in {
        type master;
        file "123.123.123.124";
};

zone "example.com" in {
        type master;
        file "example.com";
};

zone "example.net" in {
        type master;
        file "example.net";
};

// With another ~20 definitions like that

This seems very inefficient to me. Is there a way of automatically loading all files found the directory dictated by the options { directory "/some/folder" }, and assuming master for each?

1 Answer 1

8

No, there is not a way to do this within named.conf and its included files. Every zone must be explicitly defined, along with a type and data source at a bare minimum. You can have multiple zones reference the same file if the records they contain should be exact duplicates, but that is the only shortcut for this.

Other options can have their defaults set in the global options block (allow-transfer, also-notify, etc.), but you are stuck with defining every zone and the mandatory fields at a bare minimum.

For the sake of completeness, I'll mention one exception with newer versions of BIND that I strongly recommend against. You can use the new rndc addzone functionality to remotely create a zone on the fly, but what this really does is create an additional configuration file with a hashed name (i.e. randomized characters in the filename) and a .nzf suffix that BIND "knows" to load. This is very bad from a maintainability standpoint as it violates the principle of least surprise/astonishment; the main configuration file makes no reference to these additional config files and other administrators will have no idea that the contents of these files are being loaded unless they're familiar with the feature. (and very DNS admins are due to its newness)

https://ftp.isc.org/isc/bind/9.10.3rc1/doc/arm/man.rndc.html

addzone zone [class [view]] configuration

Add a zone while the server is running. This command requires the allow-new-zones option to be set to yes. The configuration string specified on the command line is the zone configuration text that would ordinarily be placed in named.conf.

The configuration is saved in a file called hash.nzf, where hash is a cryptographic hash generated from the name of the view. When named is restarted, the file will be loaded into the view configuration, so that zones that were added can persist after a restart.

This sample addzone command would add the zone example.com to the default view:

$ rndc addzone example.com '{ type master; file "example.com.db"; };'

(Note the brackets and semi-colon around the zone configuration text.)

See also rndc delzone and rndc modzone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.