I l@ve RuBoard Previous Section Next Section

2.13 Using a Single Data File for Multiple Zones

2.13.1 Problem

You want to use a single data file for multiple zones.

2.13.2 Solution

Create a "template" zone data file. Make sure that all of the owner names of records in the zone are "@" (short for the origin) or relative; that is, written without a trailing dot. For example:

@    IN    SOA    ns1.isp.net. hostmaster.isp.net. (
     2002040900
     3600
     900
     604800
     3600 )

    IN    NS    ns1.isp.net.
    IN    NS    ns2.isp.net.

    IN    MX    smtp.isp.net.

    IN    A    192.168.0.99

www IN    CNAME    @

Add zone statements to your name server's named.conf file, configuring it as primary master for the various zones, and specifying the "template" zone data file in the file substatement each time. For example:

zone "foo.example" {
    type master;
    file "db.template";
};

zone "bar.example" {
    type master;
    file "db.template";
};

zone "baz.example" {
    type master;
    file "db.template";
};

Since each zone statement sets the default origin to the domain name of the zone in the data file, the SOA record and NS records will always end up attached to the right domain name, and the rest of the records will end up "translated" into the zone.

2.13.3 Discussion

This technique will only work if all of the zones are very similar -- nearly identical, in fact. The zones must contain the same number and mix of records, and the records in the zones can only differ by the domain name of the zone. For example, if the domain name www.foo.example is an alias for a.foo.example in the foo.example zone, then www.bar.example will be an alias for a.bar.examplein the bar.example zone.

The name server must be the primary master for all of the zones; there's no way to set up an equivalent slave name server that uses the same backup zone data file for all of its zones, since name servers write fully qualified domain names to backup zone data files.

Also, none of the zones can be dynamically updated, since dynamic updates to a zone would cause the name server to rewrite the zone data file, and the rewritten zone data file would also contain fully qualified domain names.

2.13.4 See Also

Section 2.2 for understanding the default origin of a zone data file.

    I l@ve RuBoard Previous Section Next Section