1

I have to create A and NS records for 100 domains, I am able to do this the following default/common way

Example for one domain, a.com

nano /etc/bind/named.conf.default-zones

append

zone "a.com" {
        type master;
        file "/etc/bind/a.com";
};

Then create a.com zone file and add the following

nano /etc/bind/a.com

$TTL 1h
@              IN SOA          a.com.    root.a.com. (
                               2013080701      ; serial
                               3h              ; refresh
                               1h              ; retry
                               1w              ; expiry
                               1d )            ; minimum

a.com.     IN NS           a.com.
a.com.     IN A            11.11.11.11

The problem with this way is I must manually create 100 zone files and update the default-zones file and create 100 matching zone entries

I am wondering if there is a way I can do it something like the following theoretical psuedo code

nano /etc/bind/named.conf.default-zones

zone "." {
        type master;
        file "/etc/bind/all";
};


nano /etc/all

$TTL 1h
@              IN SOA          a.com.    root.a.com. (
                               2013080701      ; serial
                               3h              ; refresh
                               1h              ; retry
                               1w              ; expiry
                               1d )            ; minimum

a.com.     IN NS           a.com.
a.com.     IN A            11.11.11.11

b.com.     IN NS           b.com.
b.com.     IN A            22.22.22.22

c.com.     IN NS           c.com.
c.com.     IN A            33.33.33.33

d.com.     IN NS           d.com.
d.com.     IN A            44.44.44.44

e.com.     IN NS           e.com.
e.com.     IN A            55.55.55.55
...

This way we just have to update the all zone file and add our entries.

2

Sort of.

You can't simply put everything in '.' as in your example. Technically you could, but you would cause yourself far more issues down the road than you're trying to solve. Just don't. '.' is the root zone of all of DNS. You should already have '.' defined as a type hint zone.

You need to define every zone in the config file, but you can certainly point them all to one file.

zone "a.com" {
        type master;
        file "/etc/bind/default-zone";
};
zone "b.com" {
        type master;
        file "/etc/bind/default-zone";
};
zone "c.com" {
        type master;
        file "/etc/bind/default-zone";
};
zone "d.com" {
        type master;
        file "/etc/bind/default-zone";
};

What I personally do is a combination of the above and heavy use of the $INCLUDE directive.

More like:

zone "a.com" {
        type master;
        file "/etc/bind/a.com-zone";
};
zone "b.com" {
        type master;
        file "/etc/bind/b.com-zone";
};
zone "c.com" {
        type master;
        file "/etc/bind/c.com-zone";
};
zone "d.com" {
        type master;
        file "/etc/bind/d.com-zone";
};

In a file named say default-zone-data:

$TTL 1h
@              IN SOA          a.com.    root.a.com. (
                               2013080701      ; serial
                               3h              ; refresh
                               1h              ; retry
                               1w              ; expiry
                               1d )            ; minimum
               IN NS           ns1.example.com.
               IN NS           ns2.example.com.
               IN NS           ns3.example.com.

Then your individual zone files would look like:

a.com-zone:

$INCLUDE default-zone-data
a.com.             IN A            11.11.11.11

b.com-zone:

$INCLUDE default-zone-data
b.com.             IN A            22.22.22.22

c.com-zone:

$INCLUDE default-zone-data
c.com.             IN A            33.33.33.33

d.com-zone:

$INCLUDE default-zone-data
d.com.             IN A            44.44.44.44

It may seem like a lot of work, but you can eliminate nearly all of the manual work with a simple shell script.

0

You could just make 100 files using a script.

This is a Python example.

from jinja2 import Template

template = '''$TTL 1h
@              IN SOA          {{ zone }}    root.{{ zone }} (
                               1               ; serial
                               3h              ; refresh
                               1h              ; retry
                               1w              ; expiry
                               1d )            ; minimum

{{ zone }}     IN NS           {{ zone }}
{{ zone }}     IN A            {{ ip }}'''
dnsfile = Template(template)

zones = {
    'a.com.':'11.11.11.11',
    'b.com.':'22.22.22.22',
    'c.com.':'33.33.33.33'
}

for zone, ip in sorted(zones.items()):
    with open('/var/named/zones/{}dns'.format(zone), 'w+') as f:
        f.write(dnsfile.render(zone=zone, ip=ip))

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.