Next Previous Contents

24. DNS: Acquiring and configuring CHROOTed and SPLIT master/slave DNS servers

The daemon called "named" is the DNS or "Domain Name Server" service that converts Internet hostnames like "www.yahoo.com" to IP addresses like 204.71.177.71 (one of Yahoo's MANY TCP/IP addresses). Though there are other DNS server alternatives to ISC's BIND, it is the most common and best maintained version available. As you might have already figured out, this is a CRITICAL service for the Internet.

TrinityOS documents how to setup multiple Internet domains for full TCP/IP address subnets using both Bind9 and Bind8. It also also covers advanced redundancy and security topics such as remote secondary (backup) DNS servers and both "CHROOTed Jails" and "Split Zone" files. For the time being, TrinityOS does NOT currently cover Dynamic DNS or DNSSEC. These topics will be covered in future revisions.

What are some of these advanced topics?

To setup your own domain, the first thing you need to do is get a domain from one of the Domain Registars listed at http://www.internic.net. There are lots of them out there and price and the quality of their services varies wildly. So far, I've had great luck with http://www.directnic.net since they offer the ability via an SSL encrypted WWW page vs. old-school mechanisms like email, etc. If you have questions about other registrars you're thinking of using, send me an email and I can give you my thoughts. Next, you need to find another DNS server out on the Internet that will be a SECONDARY dns server for your chosen Internet domain(s). This backup server is for the situations when your server or Internet connection goes down and you don't want to bounce email, etc. (see Section 24 - Sendmail for more details about backup email services). Please note that getting this secondary server setup is NOT optional! Many domain registrars won't accept your domain name application without at least ONE backup domain server. Fortunately, many registrars can offer this secondary service for you for some additional fee. Again, prices vary wildly.

* If you would like to read more on HOW to get your own domain names and understand some important legal issues with Internet domain names, please see the How to acquire a Domain Name sub-section at the end of this section.

24.1 Protecting your Internet Domain Name when Making Changes

24.2 BIND version 9 vs 8 vs 4 and Figuring out what version you have:

This document is intended for BIND versons 9.1.x (and newer) as well as 8.3.x. If you are still running Bind4 or even Bind8, you really need to upgrade because you are either vunerable to ROOT hacks and/or these versions are old and are either soon to be or are already unsupported.

Just a little history:

If you are unsure what version you have installed, you can find out the version from one of two ways.

24.3 Security Warnings about previous versions of BIND

There are several MAJOR security exploits out there for older versions of Named (8.3.3-REL, 8.2.5, etc.). Make sure you are running at LEAST version 8.3.4, 9.2.2, or newer. It should be noted that 9.2.2 requires a non-vulnerable version of OpenSSL to be installed if you want to use the "--with-openssl" feature. TrinityOS doesn't currently cover this topic but the installation of 9.2.2 is highly recommended. If you aren't running the newest code, you will be vulnerable to hostile users getting ROOT access on your box!

** To stay up on the newest Bind releases, I recommend that ALL users add themselves to the BIND-announce email list given in Section 5.

This email list is ONLY for BIND version announcements and is very low on email traffic.

24.4 Downloading and compiling BIND

24.5 Creating the CHROOTed environments

Now, follow the procedures to create the required chrooted user login, group, and various files and do any required substitutions where required.


                        groupadd -g 120 chroot-dns-ext


                        groupadd -g 121 chroot-dns-int  


                        useradd -u 120 -g 120 chroot-dns-ext
                        useradd -u 121 -g 121 chroot-dns-int


  #  Since this is a CHROOTed environment, you need to make this little
  #  world look like the real one.  This means you need the required
  #  system directorys as well.

        cd /home/chroot-dns-ext

        mkdir -p etc lib dev usr/sbin var/named var/run
        chmod -R 750 /home/chroot-dns-ext
        mknod -m 666 dev/null c 1 3
        mknod -m 666 dev/zero c 1 5
        mknod -m 666 dev/random c 1 8

        cd /home/chroot-dns-int

        mkdir -p etc lib dev usr/sbin var/named var/run
        chmod -R 750 /home/chroot-dns-int
        mknod -m 666 dev/null c 1 3
        mknod -m 666 dev/zero c 1 5
        mknod -m 666 dev/random c 1 8


                        cp -f /lib/libc.so.6 /home/chroot-dns-ext/lib
                        cp -f /lib/libc.so.6 /home/chroot-dns-int/lib
                        cp -f /lib/ld-linux.so.2 /home/chroot-dns-ext/lib
                        cp -f /lib/ld-linux.so.2 /home/chroot-dns-int/lib

**NOTE: You will notice that I recommend to first COPY and then later MOVE the executables into the CHROOT'ed directory. This gives you a little more slack in case you make a mistake before you finally remove the original files.


                        cp -f /usr/sbin/named* /home/chroot-dns-ext/usr/sbin
                        chmod 750 /home/chroot-dns-ext/usr/sbin/named*
                        mv -f /usr/sbin/named* /home/chroot-dns-int/usr/sbin
                        chmod 750 /home/chroot-dns-int/usr/sbin/named*

Ok, fix the binary's file owner and group permissions:


        chown -R chroot-dns-int.chroot-dns-int /home/chroot-dns-int
        chown -R chroot-dns-ext.chroot-dns-ext /home/chroot-dns-ext

24.6 Creating the internal named.conf configuration file

NOTE: You'll notice that some lines will SEEM to have extra "."s (periods) at the end of domain names, etc. LEAVE THEM THERE!! They are supposed to be there and are CRITICAL to bind's internal file format!

/home/chroot-dns-int/etc/named.conf


// /home/chroot-dns-int/etc/named.conf for TrinityOS - 01/12/03

// Config file for a full authoritative --INTERNAL-- DNS server
//
//  This internal server will be the one use by the DNS server itself
//  and by any internal hosts as well

options {
        //Remember, this is already CHROOTed.  /var/named IS correct
                directory "/var/named";

        //You dont want the external interface to listen on this zone
                listen-on port 53 { 
                192.168.0.1; 127.0.0.1; 
                };

        // Uncommenting this might help if you have to go through a
        // firewall and things are not working out:
        // query-source address * port 53;
};


// Filter out any LAME server messages from cluttering up the SYSLOGs
        logging {
         category "lame-servers" { null; };
        };
     

zone "." {
        type hint;
        file "root.hints.db";
};

zone "0.0.127.in-addr.arpa" {
        type master;
        notify no;
        file "127.0.0.db";
};

zone "acme123.com" {
        type master;
        notify no;
        file "acme123-int.com.db";
        allow-transfer { none; };
        allow-query { 127/8; 192.168.0/24; };
};

zone "0.168.192.in-addr.arpa" {
        type master;
        notify no;
        file "192.168.0-in.addr.db";
        allow-transfer {none; };
        allow-query {127/8; 192.168.0/24; };
};

You will notice that I am filtering out LAME SERVER messages from being sent to SYSLOG. What is a "lame server"?

24.7 Creating the internal zone files


dig @a.root-servers.net . ns > /home/chroot-dns-int/var/named/root.hints.db

/home/chroot-dns-int/var/named/root.hints.db


; <<>> DiG 8.1 <<>> @a.root-servers.net . ns
; (1 server found)
;; res options: init recurs defnam dnsrch
;; got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10
;; flags: qr rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13
;; QUERY SECTION:
;;      ., type = NS, class = IN

;; ANSWER SECTION:
.                       5d10h28m15s IN NS  M.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  L.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  K.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  J.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  B.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  F.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  G.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  C.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  H.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  A.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  D.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  E.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  I.ROOT-SERVERS.NET.

;; ADDITIONAL SECTION:
M.ROOT-SERVERS.NET.     5w6d16h IN A    202.12.27.33
L.ROOT-SERVERS.NET.     5w6d16h IN A    198.32.64.12
K.ROOT-SERVERS.NET.     5w6d16h IN A    193.0.14.129
J.ROOT-SERVERS.NET.     5w6d16h IN A    198.41.0.10
B.ROOT-SERVERS.NET.     5w6d16h IN A    128.9.0.107
F.ROOT-SERVERS.NET.     5w6d16h IN A    192.5.5.241
G.ROOT-SERVERS.NET.     5w6d16h IN A    192.112.36.4
C.ROOT-SERVERS.NET.     5w6d16h IN A    192.33.4.12
H.ROOT-SERVERS.NET.     5w6d16h IN A    128.63.2.53
A.ROOT-SERVERS.NET.     5w6d16h IN A    198.41.0.4
D.ROOT-SERVERS.NET.     5w6d16h IN A    128.8.10.90
E.ROOT-SERVERS.NET.     5w6d16h IN A    192.203.230.10
I.ROOT-SERVERS.NET.     5w6d16h IN A    192.36.148.17

;; Total query time: 15115 msec
;; FROM: ns.acme123.com to SERVER: a.root-servers.net 198.41.0.4
;; WHEN: Fri Oct  1 03:02:15 1999
;; MSG SIZE  sent: 17  rcvd: 436

The following file is the REVERSE zone records for the "localhost" or loopback interface:

/home/chroot-dns-int/var/named/127.0.0.db


;
; /home/chroot-dns-int/var/named/127.0.0.db ZONE file for TrinityOS - 09/03/01
;
$TTL    86400
@               IN      SOA     ns.acme123.com. hostmaster.acme123.com. (
                            2001052800      ; serial, todays date + todays serial #
                                8H      ; Refresh
                                2H      ; Retry
                                1W      ; Expire
                                1D)     ; Minimum TTL

                          NS      ns.acme123.com.

1                  86400  PTR     localhost.acme123.com.

The following file is the FORWARD zone record for the internal ACME123.com network

/home/chroot-dns-int/var/named/acme123-int.com.db


;
; /home/chroot-dns-int/var/named/acme123-int.com ZONE file for TrinityOS - 09/03/01
;
$TTL    86400   
@       IN      SOA     ns.acme123.com. hostmaster.acme123.com. (
                                2001052800      ; serial, todays date + todays serial #
                                8H              ; refresh, seconds
                                2H              ; retry, seconds
                                1W              ; expire, seconds
                                1D )            ; minimum, seconds
        
                                NS      ns.acme123.com.     ; Inet Address of name server
                                NS      ns.backupacme.com.  ; Inet address of backup server
                                MX      10  mail.acme123.com.   ; Primary MX server

; 
; note - If you wish to directly resolve any acme123.com hosts 
;        that are currently only defined in the EXTERNAL zone 
;        files (say www.acme123.com), you MUST list them here 
;        as well since the internal zone assumes that it is 
;        authoritative for acme123.com zone and thus would never 
;        contact the external server for any other 
;        acme123.com queries.

        
roadrunner-int      86400       A       192.168.0.1
                                HINFO   "a486/160/40M" "Linux 2.0"

mail                86400       A       192.168.0.1
                                HINFO   "a486/160/40M" "Linux 2.0"


coyote              86400       A       192.168.0.2
                        HINFO   "iPentium-II/260/64M"  "Win95"
        
spare               86400       A       192.168.0.9
                        HINFO   "Unknown" "Unknown"

spare2              86400       A       192.168.0.10
                        HINFO   "Unknown" "Unknown"

The following file is the REVERSE zone record for the internal ACME123.com network

/home/chroot-dns-int/var/named/192.168.0-in.addr.db


;
; /home/chroot-dns-int/var/named/192.168.0-in.addr ZONE file for TrinityOS - 09/03/01
;
$TTL    86400
@               IN      SOA     ns.acme123.com. hostmaster.acme123.com. (
                            2001052800      ; serial, todays date + todays serial #
                                1       ; Serial
                                8H      ; Refresh
                                2H      ; Retry
                                1W      ; Expire
                                1D)     ; Minimum TTL

                          NS      ns.acme123.com.
        
1                       86400   PTR     roadrunner-int.acme123.com.
2                       86400   PTR     coyote.acme123.com.

9                       86400   PTR     spare.acme123.com.
10                      86400   PTR     spare2.acme123.com.

24.8 Creating the external named.conf configuration file

/home/chroot-dns-ext/etc/named.conf


// /home/chroot-dns-ext/etc/named.conf for TrinityOS - 11/25/02
// Config file for a full authoritative --EXTERNAL-- DNS server

options {
    //Remember, this is already CHROOTed.  /var/named IS correct
    directory "/var/named";

    //Do NOT have the server listening on localhost or the internal interface
    listen-on port 53 { 
      100.200.0.212; 
    };

    // Clean the cache every 6 hours (default is 1).
    cleaning-interval 360;

    // Do NOT respond to DNS queries for any domains other than local zones
    //
    //   All remote DNS lookups for this host and any internal machines will 
    //   be served from the INTERNAL DNS server
    recursion no;

    // Uncommenting this might help if you have to go through a
    // firewall and things are not working out:
   // query-source address * port 53;
};

zone "." {
        type hint;
        file "root.hints.db";
};

zone "acme123.com" {
        type master;
        notify yes;
        file "acme123.com.db";
        allow-transfer {
           102.200.0.25/32;
        };
};

zone "212.0.200.100.in-addr.arpa" {
        type master;
        notify yes;
        file "212.0.200.100.db";
    allow-transfer {
      102.200.0.25/32;
        };
};

24.9 Creating the external zone files


                dig @a.root-servers.net . ns > /home/chroot-dns-ext/var/named/root.hints.db

/home/chroot-dns-ext/var/named/root.hints.db


; <<>> DiG 8.1 <<>> @a.root-servers.net . ns 
; (1 server found)
;; res options: init recurs defnam dnsrch
;; got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10
;; flags: qr rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13
;; QUERY SECTION:
;;      ., type = NS, class = IN

;; ANSWER SECTION:
.                       5d10h28m15s IN NS  M.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  L.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  K.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  J.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  B.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  F.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  G.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  C.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  H.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  A.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  D.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  E.ROOT-SERVERS.NET.
.                       5d10h28m15s IN NS  I.ROOT-SERVERS.NET.

;; ADDITIONAL SECTION:
M.ROOT-SERVERS.NET.     5w6d16h IN A    202.12.27.33
L.ROOT-SERVERS.NET.     5w6d16h IN A    198.32.64.12
K.ROOT-SERVERS.NET.     5w6d16h IN A    193.0.14.129
J.ROOT-SERVERS.NET.     5w6d16h IN A    198.41.0.10
B.ROOT-SERVERS.NET.     5w6d16h IN A    128.9.0.107
F.ROOT-SERVERS.NET.     5w6d16h IN A    192.5.5.241
G.ROOT-SERVERS.NET.     5w6d16h IN A    192.112.36.4
C.ROOT-SERVERS.NET.     5w6d16h IN A    192.33.4.12
H.ROOT-SERVERS.NET.     5w6d16h IN A    128.63.2.53
A.ROOT-SERVERS.NET.     5w6d16h IN A    198.41.0.4
D.ROOT-SERVERS.NET.     5w6d16h IN A    128.8.10.90
E.ROOT-SERVERS.NET.     5w6d16h IN A    192.203.230.10
I.ROOT-SERVERS.NET.     5w6d16h IN A    192.36.148.17

;; Total query time: 15115 msec
;; FROM: ns.acme123.com to SERVER: a.root-servers.net 198.41.0.4
;; WHEN: Fri Oct  1 03:02:15 1999
;; MSG SIZE  sent: 17  rcvd: 436

The following file is the FORWARD zone records for the external ACME123.com network

/home/chroot-dns-ext/var/named/acme123.com.db


;
; /home/chroot-dns-ext/var/named/acme123.com ZONE file for TrinityOS - 09/03/01
;
$TTL    86400   
@       IN      SOA     ns.acme123.com. hostmaster.acme123.com. (
                                2001052800      ; serial, todays date + todays serial #
                                8H              ; refresh, seconds
                                2H              ; retry, seconds
                                1W              ; expire, seconds
                                1D )            ; minimum, seconds
        
               NS      ns.acme123.com.      ; Inet Address of name server
               NS      ns.backupacme.com.   ; Inet address of backup server
        
               MX   10 mail.acme123.com.    ; Primary Mail Exchanger
        

ns              86400   A       100.200.0.212
                                HINFO   "a486/160/40M" "Linux 2.0"
        
mail            86400   A       100.200.0.212
                                HINFO   "a486/160/40M" "Linux 2.0"
        

ftp             86400   CNAME   ns
        
roadrunner      86400   CNAME   ns

The following file is the REVERSE zone records for the external ACME123.com network:

/home/chroot-dns-ext/var/named/212.0.200.100.db


;
; /home/chroot-dns-ext/var/named/212.0.200.100-in.addr ZONE file for TrinityOS - 09/03/01
;
$TTL    86400
@       IN      SOA     ns.acme123.com. hostmaster.acme123.com. (
                    2001052800      ; serial, todays date + todays serial #
                        8H      ; Refresh
                        2H      ; Retry
                        1W      ; Expire
                        1D)     ; Minimum TTL

                    NS      ns.acme123.com.    ; Inet Address of name server
                    NS      ns.backupacme.com. ; Inet address of backup server

212.0.200.100.in-addr.arpa. IN PTR     ns.acme123.com.

24.10 Fixing final CHROOTed permissions and ownerships


        chown -R chroot-dns-int.chroot-dns-int /home/chroot-dns-int
        chown -R chroot-dns-ext.chroot-dns-ext /home/chroot-dns-ext

24.11 Tuning How NAMED loads the SPLIT zone file configuration

Ok, time for the glue. You need to change the way that DNS loads the server up to recognize the new CHROOT layout and to load the SPLIT servers:

Redhat users:


                        [ -f /usr/sbin/named ] || exit 0
                        .
                        .
                        .
                        [ -f /etc/named.conf ] || exit 0

to:


                        [ -f /home/chroot-dns-int/usr/sbin/named ] || exit 0
                        [ -f /home/chroot-dns-ext/usr/sbin/named ] || exit 0

                        [ -f /home/chroot-dns-int/etc/named.conf ] || exit 0
                        [ -f /home/chroot-dns-ext/etc/named.conf ] || exit 0


#!/bin/sh
#
# named           This shell script takes care of starting and stopping
#                 named (BIND DNS server).
#
# chkconfig: - 55 45
# description: named (BIND) is a Domain Name Server (DNS) \
# that is used to resolve host names to IP addresses.
# probe: true


# ----------------------------------------------------------------------------
# # TrinityOS-named
# v11/25/02
#
# Part of the copyrighted and trademarked TrinityOS document.
# <url url="http://www.ecst.csuchico.edu/~dranch">
#
# Written and Maintained by David A. Ranch
# dranch at trinnet dot net
#
#
#  NOTE: It's IMPORTANT that you edit this file and enable the correct 
#        version of Bind that you plan on running.  To disable a specific 
#        version, place "#" charecters in the front of the respective lines.
#
#        Bind9 is the TrinityOS default setting.
#
#
# Updates
# -------
# 11/25/02 - Updated some of the comments
#
# 03/05/01 - Updated the file to support the loading of Bind9
#
# 01/28/01 - Added a few CR-LFs to clean up the output between starting
#            the internal and external zones
# 10/07/00 - Added the start-int, start-ext, stop-int, and stop-ext functions
#
# ----------------------------------------------------------------------------


# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /home/chroot-dns-int/usr/sbin/named ] || exit 0
[ -f /home/chroot-dns-ext/usr/sbin/named ] || exit 0

[ -f /home/chroot-dns-int/etc/named.conf ] || exit 0
[ -f /home/chroot-dns-ext/etc/named.conf ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in

       start)
            # Start daemons.
            echo -n "Starting named-int: "

            #Bind9 - Use this setup if you are using Bind9
            #
            daemon /home/chroot-dns-int/usr/sbin/named -u chroot-dns-int -t /home/chroot-dns-int

            #Bind8 - # out the "daemon" line above and un-# out the line below
            #        if you are running Bind8
            #
            #daemon /home/chroot-dns-int/usr/sbin/named -u chroot-dns-int -g chroot-dns-int -t /home/chroot-dns-int

            RETVAL=$?
            [ $RETVAL -eq 0 ] && touch /var/lock/subsys/named-int       

            sleep 5

            echo -e "\r"
            echo -n "Starting named-ext: "

            #For some reason, this server won't load with the "daemon" line in 
            # front - if you have a solution for this, please let me know
 
            #Bind9 - Use this setup if you are using Bind9
            #
            /home/chroot-dns-ext/usr/sbin/named -u chroot-dns-ext -t /home/chroot-dns-ext

            #Bind8 - # out the "daemon" line above and un-# out the line below
            #        if you are running Bind8
            #
            #/home/chroot-dns-ext/usr/sbin/named -u chroot-dns-ext -g chroot-dns-ext -t /home/chroot-dns-ext

            RETVAL=$?
            [ $RETVAL -eq 0 ] && touch /var/lock/subsys/named-ext
            echo -e "\r"
         ;;

        start-int)
            # Start daemons.
            echo -n "Starting named-int: "

            #For some reason, this server won't load with the "daemon" line in 
            # front - if you have a solution for this, please let me know

            #Bind9 - Use this setup if you are using Bind9
            #
            /home/chroot-dns-int/usr/sbin/named -u chroot-dns-int -t /home/chroot-dns-int

            #Bind8 - # out the "daemon" line above and un-# out the line below
            #        if you are running Bind8
            #
            #/home/chroot-dns-int/usr/sbin/named -u chroot-dns-int -g chroot-dns-int -t /home/chroot-dns-int

            RETVAL=$?
            [ $RETVAL -eq 0 ] && touch /var/lock/subsys/named-int
            echo -e "\r"
        ;;

        start-ext)
            echo -n "Starting named-ext: "

            #For some reason, this server won't load with the "daemon" line in 
            # front - if you have a solution for this, please let me know

            #Bind9 - Use this setup if you are using Bind9
            #
            /home/chroot-dns-ext/usr/sbin/named -u chroot-dns-ext -t /home/chroot-dns-ext

            #Bind8 - # out the "daemon" line above and un-# out the line below
            #        if you are running Bind8
            #
            /home/chroot-dns-ext/usr/sbin/named -u chroot-dns-ext -g chroot-dns-ext -t /home/chroot-dns-ext

            RETVAL=$?
            $RETVAL -eq 0 ] && touch /var/lock/subsys/named-ext
            echo -e "\r"
        ;;

        stop)
          # Stop daemons.       
                   echo -n "Shutting down named: "
           killproc named
           RETVAL=$?
           [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named-int && rm -f /var/lock/subsys/named-ext
           echo -e "\r"
        ;;

        stop-int)
            # Stop INT daemons.
            echo -n "Shutting down named-int: "
            kill `ps ax | grep chroot-dns-int/usr/sbin/named | grep -v -e grep | awk '{print $1}'`
            RETVAL=$?
            [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named-int
            echo -e "\r"
        ;;

        stop-ext)
            # Stop EXT daemons.
            echo -n "Shutting down named-ext: "
            kill `ps ax | grep chroot-dns-ext/usr/sbin/named | grep -v -e grep | awk '{print $1}'`
            RETVAL=$?
            [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named-ext
            echo -e "\r"
        ;;

        status)
          /usr/sbin/ndc status
          exit $?
        ;;


        restart)
           $0 stop
           $0 start
        ;;


        reload)
           /usr/sbin/ndc reload
           exit $?
        ;; 


        probe)
           # named knows how to reload intelligently; we don't want linuxconf
           # to offer to restart every time
           /usr/sbin/ndc reload >/dev/null 2>&1 || echo start
           exit 0
        ;;

 
        *)
          echo "Usage: named {start|start-int|start-ext|stop|stop-int|stop-ext|status|restart}"
        exit 1
esac
exit $RETVAL

24.12 Fixing SYSLOGing to understand the new CHROOTed setup


        daemon syslogd -a /home/chroot-dns-int/dev/log -a /home/chroot-dns-ext/dev/log -m 0

Now, configure your machine to use the local DNS server by editing /etc/resolv.conf


        search acme123.com 
        nameserver 127.0.0.1

        #Backup - your ISP's DNS servers
        #nameserver 10.200.200.69
        #nameserver 10.200.200.96

Next, make sure that your machine is prepped to use DNS:

Slackware: /etc/host.conf


                order hosts, bind
                multi on

Redhat: /etc/nsswitch.conf

Change the "hosts" line to read:


                                "hosts:      files dns"

Also, I would recommend to DELETE all instances of NIS from each line of this file UNLESS you *ARE* using NIS, NIS+, etc!

24.13 Starting up and testing BIND

Ok, getting close! Now, make sure that BIND is enabled to load upon boot.

24.14 Possible Bind errors upon load

24.15 Enabling Bind to load upon future boots

24.16 Changes for Bind9

As I mentioned before, TrinityOS currently doesn't currently cover advanced topics like Dynamic DNS, DNSSEC, etc. Some of these features are very cool and they WILL be covered some time in the future.

Anyway, for now, I wanted to mention that the "nslookup" that we are all familiar with is going away in favor of the "dig" and "host" commands instead. I recommend that you start getting used to using the "dig" and "host" commands. If you need to continue to use "nslookup", you should consider the following alias to avoid the annoying nslookup warnings:

/etc/bashrc


 alias nslookup='nslookup -silent'

24.17 Supporting more than one Internet Domain name on this DNS server

Having your Linux box do DNS for more that just ONE domain is VERY simple. If you want to do this, all you have to do is:

  1. Create another FORWARD zone file (e.g. another-domain.com) for your new domain.

    e.g. use the old acme123.com files from above as a template for your new /home/chroot-dns-ext/var/named/another-domain.com.db file

  2. Edit the /home/chroot-dns-ext/etc/named.conf file to:
    1. Add the loading of the new /var/named/newdomain.com.db zone file just like you did for the acme123.com zone file.

    2. Allow your remote secondary DNS servers to be able access this new domain's zone file

    3. Restart Bind

24.18 Setting up Secondary (BACKUP) DNS servers

If you want someone else's DNS server to be a secondary DNS server for your domain(s) *OR* you want your DNS server to be a secondary for someone else's domain(s), follow these following steps.


    zone "acme123.com." {
      type slave;
      file "acme123.com.db";
      masters { 100.200.0.212; };
      allow-transfer { none; };
    };

    zone "212.0.200.100.in-addr.arpa." {
      type slave;
      file "212.0.200.100.db";
      masters { 100.200.0.212; };
      allow-transfer { none; };
    };

NOTE: If the remote domain actually had multiple IPs or a "subnet of IPs" (typically 5 or more IP addresses), you would need a slightly different configuration. The following example would be correct if the remote domain had -8- IP allocated.


                zone "128/29.0.200.100.in-addr.arpa." {
                  type slave;
                  file "128.0.200.100.db";
                  masters { 100.200.0.129; };
                  allow-transfer { none; };
                };

Basically, you need to understand that:

The IP addresses the remote site was given an address range of 100.200.0.128 through .135 with a subnet mask of 255.255.255.248 (a /29).

Then, with the not-so-obvious DNS syntax from RFC 2317, you read the top line as:

Yes, its weird syntax and NOT obvious (try even reading the RFC!) but it works fine.


                        touch /home/chroot-dns-ext/var/named/acme123.com.db

Once everything is working fine, be SURE to follow the "aliases" instruction in Section 18.

24.19 Gotchas with Master DNS servers being down for long periods of time

IMPORTANT:

24.20 Secondary DNS Design considerations

It should be mentioned that there is a very interesting and SERIOUS design issue that needs to be considered when setting up secondary zones with a split DNS setup. Say you have acme123.com running on both the INTERNAL -and- EXTERNAL processes on a server (same as the TrinityOS example set above).

The problem arises when you secondary for some remote domain(s) on the Internet. The email server for your domain then tries to send email to that remote email server. The process goes something as follows:

Not very useful eh?

There are TWO valid solutions:

24.21 Automating the maintenance of the root-hints.db file

Ok, now DNS is hopefully working for your new connection. Next, I recommend that you implement the following script to maintain the root-hints file. Remember, the ROOT DNS server addresses change from time time. This script borrowed from the tldp.org's DNS-HOWTO (with a few changes on my behalf [should be in the DNS-HOWTO now]) makes sure things are occasionally updated:

/usr/local/sbin/root-hints-update

<root-hints-update START>


#!/bin/bash
#
# Part of the copyrighted and trademarked TrinityOS document.
# http://www.ecst.csuchico.edu/~dranch/LINUX/index-linux.html
#
# Written and Maintained by David A. Ranch
# dranch at trinnet dot net
#
#
# Update the nameserver cache information file once per month.
# This is run automatically by a cron entry.
#
# v2.6 - Fixed an error where the root.hints.new file was missing
#        from the "results" email.  The script is now deleting the 
#        "results" file and is using all absolute paths.  Finally, the
#        script is again sending the "result" output as well.
# v2.5 - Fixed a filename error where the final status email was using
#        int/root.hints.new instead of int/root.hints.db
#      - Removed the line trying to delete a non-existant file
#      - Added some echo statements to make things a little
#        clearer 
# v2.4 - Updated the dig info lookup from ns.internic.net to
#        a.root-servers.net 
# v2.3 - Updated the initial CD into one of the real CHROOTed dirs
#        vs. /var/named.  The old script was also leaving a stray NEW
#        file in the EXT directory.  Because of all this, the email
#        notification would show an old root.hints file though DNS
#        would have the correct updated file.
# v2.2 - Change getting the hints file from rs.internic.net to ns.internic.
#        net
# v2.1 - Fixed a typo in the CHMOD of the external root-hints.sb file
#      - Fixed the file ownership of the internal root-hints.db file
#      - Changed the default path of where the new root.hints.new file 
#        is to be placed
#      - Updated to have a backup copy of the INTERNAL hints file and not
#        just have an EXTERNAL backup
# v2.0 - Updated the script to support dual zone files
# v1.3 - Updated the script to show more verbose FAILURE logs.
#        Thanks to jon.marks@novatek.co.nz for the ideas
#
# v1.2 - added the test if no ROOT-SERVERS were returned
# v1.1 - added the test if the result had a SERV-FAIL
# v1.0 - original script from the DNS-HOWTO

echo -e "Running /home/chroot-dns/ext/var/named/root-hints-update..\n" 
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:

echo "Entering chroot-dns-ext" 
cd /home/chroot-dns-ext/var/named

echo "Getting current root servers list.." 
dig @a.root-servers.net . ns > /home/chroot-dns-ext/var/named/root.hints.new \
2> /home/chroot-dns-ext/var/named/result

DIG_OUTCOME=FAIL
if [ `grep -c SERVFAIL /home/chroot-dns-ext/var/named/root.hints.new ` = 0 \
] && [ `grep -c ROOT-SERVERS /home/chroot-dns-ext/var/named/root.hints.new` -gt 0 ]
   then
        DIG_OUTCOME=SUCCESS
        echo "   - Copying new hints file to the EXT named directory"   
        mv -f /home/chroot-dns-ext/var/named/root.hints.db /home/chroot-dns-ext/var/named/root.hints.db.old
        cp -f /home/chroot-dns-ext/var/named/root.hints.new /home/chroot-dns-ext/var/named/root.hints.db
        chown chroot-dns-ext:chroot-dns-ext /home/chroot-dns-ext/var/named/root.hints.db
        chmod 444 /home/chroot-dns-ext/var/named/root.hints.db

        echo "   - Moving new hints file to the INT named directory" 
        mv -f /home/chroot-dns-int/var/named/root.hints.db /home/chroot-dns-int/var/named/root.hints.db.old
        mv /home/chroot-dns-ext/var/named/root.hints.new /home/chroot-dns-int/var/named/root.hints.db
        chown chroot-dns-int:chroot-dns-int /home/chroot-dns-int/var/named/root.hints.db
        chmod 444 /home/chroot-dns-int/var/named/root.hints.db

        echo "Restarting both INT and EXT name.."  
        echo -n "Restarting named: " >> result
        # note:  We dont use restart since old Redhat didn't support it
        /etc/rc.d/init.d/named stop >> /home/chroot-dns-ext/var/named/result
        /etc/rc.d/init.d/named start >> /home/chroot-dns-ext/var/named/result
fi

echo "Emailing the results to root.."
(
        echo "To: hostmaster <root>"
        echo "From: system <root>"
        echo "Subject: TrinityOS DNS monthly root.hints.db update status: $DIG_OUTCOME."
        echo
        cat /home/chroot-dns-ext/var/named/result
        cat /home/chroot-dns-ext/var/named/root.hints.db 
        echo

) | /usr/sbin/sendmail -t
echo "Done."
rm -f /home/chroot-dns-ext/var/named/result
exit 0

<root-hints-update STOP>

Now, make it executable and readable ONLY by the root user:


                chmod 700 /usr/local/sbin/root-hints-update

Finally, put it in the cron job to run monthly:

Redhat:


        ln -s /usr/local/sbin/root-hints-update /etc/cron.monthly/root-hints-update

Slackware:

- Edit "/var/spool/cron/crontab/root" and add this line to the bootom of the file:


                02 3 1 * *      /usr/local/sbin/root-hints-update

That's it!

24.22 How to acquire an Internet Domain Name

To get your own Internet domain, you need:

  1. A pre-selected Internet domain name that isn't already taken. You can check to see if your desired domain is available by going to: http://www.internic.net or use the UNIX "whois" command. If the domain you want is already gone, don't forget to try the other suffixes like .com, .net, .org and now the new TLDs like .biz, .info, .name, .museum, .coop, .aero, and .pro. You should also know that many other countries are pushing users to use their domain space. For example, .cc and .tv are fairly popular with some people.

    NOTE: U.S. laws are about to change in the Internet. Currently, sleazy Internet users have been reserving domain names like cheezewiz.com and making the rightful owners (Kraft Corporation) pay ransoms to get them back.

    In 2000, companies that owned standard name trademarks to names, like CheeseWiz, finally got the LEGAL rights get to those domains. On the flip side, even if you had the domain superdupergizo.com for years and sold even gizmos with that name, someone might get that name "SuperDumoGizmo" trademarked. If that happened, they would then have the LEGAL right to take that domain away from you. Sucks huh?

    How can you protect YOUR domain? You might also want to get your domain trademarked. You might not care too much about this but some people will NEED TO. Please also understand that if you get a trademark for for the name and you already secured the .com domain name, you will then have legal grounds to kick people off the .net and .org domains as well. Personally, I think it will be cheaper in the long run if you just register ALL three domain name suffixes (.com, .net, .org) at one time. But if you then start to think about the new .biz, .info, etc. domains and this can be a LOT of money. Overall, the whole situation is a mess and I'm not sure what is the least-evil way of protecting your domain.

  2. You need agreements with (1) or more EXISTING /remote/ DNS servers their to be your secondary (backup) DNS servers. You will have to coordinate this with the remote DNS administrators but it isn't too hard. It should also be noted that many Domain registrars can act a secondary DNS server for an addition fee. As it stands, the setup of the secondary DNS support is fully documented in TrinityOS's DNS section.

  3. A permanent Internet connection with a static IP --OR-- you can sign up with some of those dynamic DNS providers and THEY can then update their zones to you.

  4. A credit card (makes things easier but they can also bill you too for bulk requests). Each domain currently costs different amounts depending which Registrar you use. DirectNIC charges $15 (U.S.) per domain but other Registrars might be even cheaper. Do your homework and see what you find.

    NOTE: Fortunately, you can usually deduct this cost from your taxes.

  5. Now, with all this information (IP addresses, etc), go to http://www.internic.net and pick a Registrar. The incumbant registrar is Network Solutions (NSI) but my experience with them hasn't been very good. Though I can't recommend one registrar over another, I encourage you to research it a little. If you have good/bad luck with some of these new players, I'd love to hear from you.

  6. Follow the prompts and enter in your domain name(s). Then click on either "reserve" or "register".

    NOTE: In the past, all DNS registrations were done via an email-only system. It was confusing at times and a pain. The new systems are usually SSL WWW based and is much easier to use. Interestingly enough, NSI would let you fill things out via a WWW form but it still would email you the completed form and then expect you to EMAIL it back to them. Lame. This might not be the case anymore as I don't use nor recommend NSI anymore.

    NOTE #2: Do not put in bogus data for any of the fields thinking it will keep your information private from SPAMMERs, etc.. Registrars check the info and if it doesn't all check, they will deny you the domain. They need your snail mailing address for your receipt and telephone numbers in case your DNS server, etc. goes down, is hacked into, etc. Them having your phone number is more valuable than you might think.

    NOTE #3: If you chose to use Network Solutions, you might be filling out the new Contact Information area, you might see the section for security. There are three types:


            MAIL-FROM:  This means that any changes to your domain must come
                                    from an email address from your domain and it is
                                    the default setting.  
    
                                    DO NOT USE THIS OPTION.
    
                                    Its too simple for remote people to forge email.
                                    Because of this, many people have had their domains
                                    STOLEN from them because of this weak link.
    
            CRYPT:          This is a password encrypted setup.  This is pretty good 
                                    as long as you use a GOOD password.  See 
                    <ref id="sect-8" name="Section 8"> in TrinityOS for how to 
                    pick good passwords.
    
            PGP:            This is the ultimate in security and you need to submit your 
                                    public PGP key to the Internic.  BE WARNED:
                                    If you change your PGP key often (your need to do this), 
                                    you might lock yourself out of your domain and you will 
                                    have to call the Internic direct.
      
    

    If you DO NOT SEE these fields, don't worry. Once you finish your domain registration, go back to:

    http://www.networksolutions.com/cgi-bin/itts/handle

    and change it there.

  7. When the Registrar asks you for an email address, do NOT use an email address that will be behind this new domain. Why? Until you get this DNS system fully running, any email from the Registrar sent to this email will be lost! Get it? Putting it another way, if you have problems with your domain and email isn't working, you WON'T be able to fix it because some registrars expect Domain change emails to come FROM the problem DNS domain. Stupid.. very stupid. Eh.. But.. don't worry, once everything works uine, you can go back and change this address.

  8. After that, its pretty simple and VERY fast.

If you need more info on DNS, follow this great HOWTO:

ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/DNS-HOWTO


Next Previous Contents