How to create DNS subdomains Linux

domain-name-systemsubdomain

i'm trying to build a DNS Server with sub domains, where i have domain name padence.com and beneath that i need two more sub domains to be added like aa.padence.com and bb.padence.com . I have setup the DNS Server into a chrooted env based on my learning, However i'm unable to get the clear understanding on how to create subdomains , i searched around the web and all possible location i think of but didn't get a clear understanding.

Do i need to create separate zone for both subdomains (Forward & reverse) apart from the one which needs in named.conf.

Below is my configuration, please provide your expert inputs and suggestion to help me setup the DNS with subdomains.

1) Forward lookup zone

# cat  /var/named/chroot/var/named/padence.com.forward.zone
$TTL 1D
@       IN SOA  padence.com.            root.padence.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@               NS      sj-karntest1.padence.com.
                A       127.0.0.1
sj-karntest1    A       192.18.12.235
sj-karntest2    A       192.18.18.209

2) Reverse lookup zone

# cat  /var/named/chroot/var/named/padence.com.reverse.zone
    $TTL 1D
    @       IN SOA   padence.com.          root.padence.com. (
                                            0       ; serial
                                            1D      ; refresh
                                            1H      ; retry
                                            1W      ; expire
                                            3H )    ; minimum
    @       NS      sj-karntest1.padence.com.
            A       127.0.0.1
            PTR     localhost.
    235     PTR     sj-karntest1.
    209     PTR     sj-karntest2.

named.conf

# cat /var/named/chroot/etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
        listen-on port 53 { 127.0.0.1;192.18.12.235; };
        #listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { any; };
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";
};


logging {
  channel log_to_file {
    file "/var/log/bind.log" versions 3 size 5m;
    severity info;
    print-time yes;
    print-severity yes;
    print-category yes;
  };

  #Only for trouble-shooting - could be noisy
  category queries {
    log_to_file;
  };
  #Only for trouble-shooting - could be noisy
  category resolver {
    log_to_file;
  };

  category default {
    log_to_file;
  };
  category dnssec {
    log_to_file;
  };
  category security {
    log_to_file;
  };
  category update-security {
    log_to_file;
  };
};

// ZONE SECTION
zone "." IN {
        type hint;
        file "named.ca";
};

zone "padence.com." IN {
        type master;
        file "padence.com.forward.zone";
        allow-update { none; };
};

zone "12.18.192.in-addr.arpa" IN {
        type master;
        file "padence.com.reverse.zone";
        allow-update { none; };
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

Thanks so much for your help in advanced.

Best Answer

To create subdomain, use NS RR (Resource Record):

# cat  /var/named/chroot/var/named/padence.com.forward.zone
$TTL 1D
@       IN SOA  padence.com.            root.padence.com. (
                                        1       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@               NS      sj-karntest1.padence.com.
                A       127.0.0.1
sj-karntest1    A       192.18.12.235
sj-karntest2    A       192.18.18.209
aa              NS      sj-karntest1.padence.com.
bb              NS      sj-karntest1.padence.com.

Then create two zones in your named.conf

zone "aa.padence.com." IN {
        type master;
        file "aa.padence.com.forward.zone";
        allow-update { none; };
};

zone "bb.padence.com." IN {
        type master;
        file "bb.padence.com.forward.zone";
        allow-update { none; };
};

And finally create zone files for these two subdomains - here you can find sample for aa.padence.forward.com

# cat  /var/named/chroot/var/named/aa.padence.com.forward.zone
$TTL 1D
@       IN SOA  aa.padence.com.            root.padence.com. (
                                        1       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@               NS      sj-karntest1.padence.com.
                A       127.0.0.1
; this is entry for www.aa.padence.com
www             A       192.18.12.235

You do not need to create separete reverse zones for these.