Configuring a Regular Name Server



Configuring a Regular Name Server

For the purposes of this tutorial, assume your ISP assigned you the subnet 97.158.253.24 with a subnet mask of 255.255.255.248 (/29).

Configuring resolv.conf

You'll have to make your DNS server refer to itself for all DNS queries by configuring the /etc/resolv.conf file to reference localhost only.

     nameserver 127.0.0.1

Configuring named.conf

The named.conf file contains the main DNS configuration and tells BIND where to find the configuration files for each domain you own. This file usually has two zone areas:

  • Forward zone file definitions list files to map domains to IP addresses

  • Reverse zone file definitions list files to map IP addresses to domains

In this example, you'll set up the forward zone for www.my-web-site.org by placing entries at the bottom of the named.conf file. The zone file is named my-site.zone, and, although not explicitly stated, the file my-site.zone should be located in the default directory of /var/named/chroot/var/named in a chroot or in /var/named in a regular one. Use the code:

     zone "my-web-site.org" {

         type master;
         notify no;
         allow-query { any; };
         file "my-site.zone";

     };

In addition, you can insert additional entries in the named.conf file to reference other Web domains you host. Here is an example for another-site.com using a zone file named another-site.zone:

     zone "another-site.com" {

         type master;
         notify no;
         allow-query { any; };
         file "another-site.zone";

     };

Note

The allow-query directive defines the networks that are allowed to query your DNS server for information on any zone. For example, to limit queries to only your 192.168.1.0 network, you could modify the directive to:

     allow-query { 192.168.1.0/24; };


Next, you have to format entries to handle the reverse lookups for your IP addresses. In most cases, your ISP handles the reverse zone entries for your public IP addresses, but you will have to create reverse zone entries for your SOHO/home environment using the 192.168.1.0/24 address space. This isn't important for the Windows clients on your network, but some Linux applications require valid forward and reverse entries to operate correctly.

The forward domain lookup process for mysite.com scans the FQDN from right to left to get increasingly more specific information about the authoritative servers to use. Reverse lookups operate similarly by scanning an IP address from left to right to get increasingly specific information about an address.

The similarity in both methods is that increasingly specific information is sought, but the noticeable difference is that for forward lookups the scan is from right to left, and for reverse lookups the scan is from left to right. This difference can be seen in the formatting of the zone statement for a reverse zone in /etc/named.conf file where the main in-addr.arpa domain, to which all IP addresses belong, is followed by the first three octets of the IP address in reverse order. This order is important to remember or else the configuration will fail. This reverse zone definition for named.conf uses a reverse zone file named 192-168-1.zone for the 192.168.1.0/24 network:

     zone "1.168.196.in-addr.arpa" {
         type master;
         notify no;
         file "192-168-1.zone";
     };

Configuring the Zone Files

You need to keep a number of things in mind when configuring DNS zone files:

  • In all zone files, you can place a comment at the end of any line by inserting a semi-colon character then typing in the text of your comment.

  • By default, your zone files are located in the directory /var/named or /var/named/chroot/var/named.

  • Each zone file contains a variety of records (SOA, NS, MX, A, and CNAME) that govern different areas of BIND.

    Take a closer look at these entries in the zone file.

Time to Live Value

The very first entry in the zone file is usually the zone's time to live (TTL) value. Caching DNS servers cache the responses to their queries from authoritative DNS servers. The authoritative servers not only provide the DNS answer but also provide the information's time to live, which is the period for which it's valid.

The purpose of a TTL is to reduce the number of DNS queries the authoritative DNS server has to answer. If the TTL is set to three days, then caching servers use the original stored response for three days before making the query again:

     $TTL 3D

BIND recognizes several suffixes for time-related values. A D signifies days, a W signifies weeks, and an H signifies hours. In the absence of a suffix, BIND assumes the value is in seconds.

DNS Resource Records

The rest of the records in a zone file are usually BIND resource records. They define the nature of the DNS information in your zone files that's presented to querying DNS clients. They all have the general format:

     Name Class Type Data

There are different types of records for mail (MX), forward lookups (A), reverse lookups (PTR), aliases (CNAME) and overall zone definitions, Start of Authority (SOA). The data portion is formatted according to the record type and may consist of several values separated by spaces. Similarly, the name is also subject to interpretation based on this factor.

The SOA Record

The first resource record is the SOA record, which contains general administrative and control information about the domain. It has the format:

     Name Class Type Name-Server Email-Address Serial-No Refresh Retry
     Expiry Minimum-TTL

The record can be long, and will sometimes wrap around on your screen. For the sake of formatting, you can insert new line characters between the fields as long as you insert parenthesis at the beginning and end of the insertion to alert BIND that part of the record will straddle multiple lines. You can also add comments to the end of each new line separated by a semicolon when you do this. Here is an example:

     @    IN    SOA    ns1.my-web-site.org. hostmaster.my-web-site.org. (
                         2004100801       ; serial #
                         4H               ; refresh
                         1H               ; retry



                    1W                ; expiry
                         1D )             ; minimum

Figure explains what each field in the record means.

The SOA Record Format

Field

Description

Name

The root name of the zone. The @ sign is a shorthand reference to the current origin (zone) in the /etc/named.conf file for that particular database file.

Class

There are a number of different DNS classes. Home/SOHO will be limited to the IN or Internet class used when defining IP address mapping information for BIND. Other classes exist for non-Internet protocols and functions but are very rarely used.

Type

The type of DNS resource record. In the example, this is an SOA resource record. Other types of records exist, which I'll cover later.

Name-server

Fully qualified name of your primary name server. Must be followed by a period.

Email-address

The e-mail address of the name server administrator. The regular @ in the e-mail address must be replaced with a period instead. The e-mail address must also be followed by a period.

Serial-no

A serial number for the current configuration. You can use the format YYYYMMDD with single digit incremented number tagged to the end to provide an incremental value that provides some editing information.

Refresh

Tells the slave DNS server how often it should check the master DNS server. Slaves aren't usually used in home/SOHO environments.

Retry

The slave's retry interval to connect the master in the event of a connection failure. Slaves aren't usually used in home/SOHO environments.

Expiry

Total amount of time a slave should retry to contact the master before expiring the data it contains. Future references will be directed towards the root servers. Slaves aren't usually used in home/SOHO environments.

Minimum-TTL

There are times when remote clients will make queries for subdomains that don't exist. Your DNS server will respond with a no domain or NXDOMAIN response that the remote client caches. This value defines the caching duration your DNS includes in this response.


So in the example, the primary name server is defined as ns1.my-web-site.org with a contact e-mail address of hostmaster@my-web-site.org. The serial number is 2004100801 with refresh, retry, expiry, and minimum values of 4 hours, 1 hour, 1 week, and 1 day, respectively.

NS, MX, A, PTR, and CNAME Records

Like the SOA record, the NS, MX, A, PTR, and CNAME records each occupy a single line with a very similar general format. Figure outlines the way they are laid out.

NS, MX, A, PTR, and CNAME Record Formats

Record Type

Field Descriptions

Name Field

Class Field[2]

Type Field

Data Field

NS

Usually blank[1]

IN

NS

IP address or CNAME of the name server

MX

Domain to be used for mail; usually the same as the domain of the zone file itself.

IN

MX

Mail server DNS name

A

Name of a server in the domain

IN

A

IP address of server

CNAME

Server name alias

IN

CNAME

"A" record name for the server

PTR

Last octet of server's IP address

IN

PTR

Fully qualified server name


[2] For most home/SOHO scenarios, the Class field will always be IN or Internet. You should also be aware that IN is the default Class, and BIND assumes a record is of this type unless otherwise stated.

[1] If the search key to a DNS resource record is blank, it reuses the search key from the previous record. For the example, this is the SOA @ sign.

If you don't put a period at the end of a host name in a SOA, NS, A, or CNAME record, BIND will automatically tack on the zone file's domain name to the name of the host. So, BIND assumes an A record with www refers to www.my-web-site.org. This may be acceptable in most cases, but if you forget to put the period after the domain in the MX record for my-web-site.org, BIND attaches the my-web-site.org at the end, and you will find your mail server accepting mail only for the domain my-web-site.org.mysite.com.

Sample Forward Zone File

Now that you know the key elements of a zone file, it's time to examine a working example for the domain my-web-site.org:

     ;
     ; Zone file for my-web-site.org
     ;
     ; The full zone file
     ;
     $TTL 3D
     @       IN      SOA    ns1.my-web-site.org. hostmaster.my-web-
     site.org. (
                            200211152       ; serial#
                            3600            ; refresh, seconds
                            3600            ; retry, seconds
                            3600            ; expire, seconds
                            3600 )          ; minimum, seconds
     ;
                     NS     www             ; Inet Address of nameserver

     my-web-site.org.   MX      10 mail         ; Primary Mail Exchanger

     ;
     localhost       A      127.0.0.1
     bigboy          A      97.158.253.26
     mail            CNAME  bigboy
     ns1             CNAME  bigboy
     www             CNAME  bigboy

Notice that in this example:

  • Server ns1.my-web-site.org is the name server for my-web-site.org. In corporate environments there may be a separate name server for this purpose. Primary name servers are more commonly called ns1 and secondary name servers ns2.

  • The minimum TTL value ($TTL) is three days, therefore remote DNS caching servers will store learned DNS information from your zone for three days before flushing it out of their caches.

  • The MX record for my-web-site.org points to the server named mail.my-web-site.org

  • ns1 and mail are actually CNAMEs or aliases for the Web server www. So here you have an example of the name server, mail server, and Web server being the same machine. If they were all different machines, then you'd have an A record entry for each:

         www           A         97.158.253.26
         mail          A         97.158u.253.134
         ns            A         97.158.253.125
    

It is a required practice to increment your serial number whenever you edit your zone file. When DNS is set up in a redundant configuration, the slave DNS servers periodically poll the master server for updated zone file information, and use the serial number to determine whether the data on the master has been updated. Failing to increment the serial number, even though the contents of the zone file have been modified, could cause your slaves to have outdated information.

Sample Reverse Zone File

Now you need to make sure that you can do a host query on all your home network's PCs and get their correct IP addresses. This is very important if you are running a mail server on your network, because sendmail typically relays mail only from hosts whose IP addresses resolve correctly in DNS. NFS, which is used in network-based file access, also requires valid reverse lookup capabilities.

This is an example of a zone file for the 192.168.1.x network. All the entries in the first column refer to the last octet of the IP address for the network, so the IP address 192.168.1.100 points to the name bigboy.my-web-site.org.

Notice how the main difference between forward and reverse zone files is that the reverse zone file only has PTR and NS records. Also the PTR records cannot have CNAME aliases.

     ;
     ; Filename: 192-168-1.zone
     ;
     ; Zone file for 192.168.1.x
     ;
     $TTL 3D
     @       IN        SOA      www.my-web-site.org. hostmaster.my-web-
     site.org. (
                                200303301          ; serial number
                                8H                 ; refresh, seconds
                                2H                 ; retry, seconds
                                4W                 ; expire, seconds
                                1D )               ; minimum, seconds
     ;
                       NS       www                ; Nameserver Address
     ;
     100                PTR      bigboy.my-web-site.org.
     103                PTR      smallfry.my-web-site.org.
     102                PTR      ochorios.my-web-site.org.
     105                PTR      reggae.my-web-site.org.

     32                 PTR      dhcp-192-168-1-32.my-web-site.org.
     33                 PTR      dhcp-192-168-1-33.my-web-site.org.
     34                 PTR      dhcp-192-168-1-34.my-web-site.org.
     35                 PTR      dhcp-192-168-1-35.my-web-site.org.
     36                 PTR      dhcp-192-168-1-36.my-web-site.org.

I included entries for addresses 192.168.1.32 to 192.168.1.36, which are the addresses the DHCP server issues. SMTP mail relay wouldn't work for PCs that get their IP addresses via DHCP if these lines weren't included.

You may also want to create a reverse zone file for the public NAT IP addresses for your home network. Unfortunately, ISPs won't usually delegate this ability for anyone with less than a Class C block of 256 IP addresses. Most home DSL sites wouldn't qualify.

What You Need to Know About NAT and DNS

The previous examples assume that the queries will be coming from the Internet with the zone files returning information related to the external 97.158.253.26 address of the Web server.

What do the PCs on your home network need to see? They need to see DNS references to the real IP address of the Web server, 192.168.1.100, because NAT won't work properly if a PC on your home network attempts to connect to the external 97.158.253.26 NAT IP address of your Web server.

Don't worry. BIND has a way around this called views. The views feature allows you to force BIND to use predefined zone files for queries from certain subnets. This means it's possible to use one set of zone files for queries from the Internet and another set for queries from your home network.

Here's a summary of how it's done:

1.
Place your zone statements in the /etc/named.conf file in one of two views sections. The first section is called internal and lists the zone files to be used by your internal network. The second view called external lists the zone files to used for Internet users.

For example, you could have a reference to a zone file called my-site.zone for lookups related to the 97.158.253.X network, which Internet users would see. This /etc/named.conf entry would be inserted in the external section. You could also have a file called my-site-home.zone for lookups by home users on the 192.168.1.0 network. This entry would be inserted in the internal section. Creating the my-site-home.zone file is fairly easy: Copy it from the my-site.zone file and replace all references to 97.158.253.X with references to 192.168.1.X.

2.
You must also tell the DNS server which addresses you feel are internal and external. To do this, you must first define the internal and external networks with access control lists (ACLs) and then refer to these lists within their respective view section with the match-clients statement. Some built-in ACLs can save you time:

  • localhost: Refers to the DNS server itself

  • localnets: Refers to all the networks to which the DNS server is directly connected

  • any: which is self explanatory

Note

You must place your localhost, 0.0.127.in-addr.arpa. and period "." zone statements in the internal views section. Remember to increment your serial numbers!


Here is a sample configuration snippet for the /etc/named.conf file I use for my home network. All the statements below were inserted after the options and controls sections in the file.

     // ACL statement

     acl "trusted-subnet" { 192.168.17.0/24; };


     view "internal" { // What the home network will see

         match-clients { localnets; localhost; "trusted-subnet"; };

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

             zone "localhost" IN {
                     type master;
                     file "localhost.zone";
                     allow-update { none; };
             };

             zone "0.0.127.in-addr.arpa" IN {
                     type master;
                     file "named.local";
                     allow-update { none; };
             };

             // IPv6 Support
             zone
     "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arp
     a" IN {
                     type master;
                     file "named.ip6.local";
                     allow-update { none; };

             };

             // Prevents lookups for broadcast addresses ending in ".255"
             zone "255.in-addr.arpa" IN {
                     type master;
                     file "named.broadcast";
                     allow-update { none; };
             };

             // Prevents lookups for network addresses ending in ".0"
             zone "0.in-addr.arpa" IN {
                     type master;
                     file "named.zero";
                     allow-update { none; };
             };

             zone "1.168.192.in-addr.arpa" IN {
                     type master;
                     file "192-168-1.zone";
                     allow-update { none; };
             };

             zone "my-web-site.org" {
                     type master;
                     notify no;
                     file "my-site-home.zone";
                     allow-query { any; };
             };

             zone "another-site.com" {
                     type master;
                     notify no;
                     file "another-site-home.zone";
                     allow-query { any; };
             };
     };


     view "external" { // What the Internet will see

         match-clients { any; };
         recursion no;


             zone "my-web-site.org" {
                     type master;
                     notify no;
                     file "my-site.zone";
                     allow-query { any; };
             };


             zone "another-site.com" {
                     type master;
                     notify no;
                     file "another-site.zone";
                     allow-query { any; };
             };
     };

In this example, I included an ACL for network 192.168.17.0 /24 called trusted-subnet to help clarify the use of ACLs in more complex environments. Once the ACL was defined, I then inserted a reference to the TRusted-subnet in the match-clients statement in the internal view. So in this case the local network (192.168.1.0 /24), the other trusted network (192.168.17.0), and localhost get DNS data from the zone files in the internal view. Remember, this is purely an example. The example home network doesn't need to have the ACL statement at all as the built in ACLs localnets and localhost are sufficient. The network won't need the trusted-subnet section in the match-clients line either.

Loading Your New Configuration Files

To load your new configuration files, first make sure your file permissions and ownership are okay in the /var/named directory:

     [root@bigboy tmp]# cd /var/named
     [root@bigboy named]# ll
     total 6
     -rw-r--r-- 1 named named 195  Jul 3 2001  localhost.zone
     -rw-r--r-- 1 named named 2769 Jul 3 2001  named.ca
     -rw-r--r-- 1 named named 433  Jul 3 2001  named.local
     -rw-r--r-- 1 root  root  763  Oct 2 16:23 my-site.zone
     [root@bigboy named]# chown named *
     [root@bigboy named]# chgrp named *
     [root@bigboy named]# ll
     total 6
     -rw-r--r-- 1 named named 195  Jul 3 2001  localhost.zone
     -rw-r--r-- 1 named named 2769 Jul 3 2001  named.ca
     -rw-r--r-- 1 named named 433  Jul 3 2001  named.local
     -rw-r--r-- 1 named named 763  Oct 2 16:23 my-site.zone
     [root@bigboy named]#

The configuration files above will not be loaded until you issue the proper command to restart the named process that controls DNS, but be sure to increment your configuration file serial number before doing this:

     [root@bigboy tmp]# service named restart

Take a look at the end of your /var/log/messages file to make sure there are no errors.

Make Sure Your /etc/hosts File is Correctly Updated

Chapter 3, "Linux Networking," explains how to correctly configure your /etc/hosts file. Some programs, such as sendmail, require a correctly configured /etc/hosts file even though DNS is correctly configured.

Configure Your Firewall

The sample network assumes that the BIND name server and Apache Web server software run on the same machine protected by a router/firewall. The actual IP address of the server is 192.168.1.100, which is a private IP address. You'll have to use NAT for Internet users to be able to gain access to the server via the chosen public IP address, namely 97.158.253.26. If your firewall is a Linux box, you may want to consider taking a look at Chapter 14, "Linux Firewalls Using iptables," which describes how to do the network address translation and allow DNS traffic through to your name server.

Fix Your Domain Registration

Remember to edit your domain registration for my-web-site.org, or whatever it is, so that at least one of the name servers is your new name server (97.158.253.26 in this case). Domain registrars, such as VeriSign and RegisterFree, usually provide a Web interface to help you manage your domain.

Once you've logged in with the registrar's username and password, you'll have to take two steps:

1.
Create a new name server record entry for the IP address 97.158.253.26 to map to ns.my-web-site.org or www.my-web-site.org or whatever your name server is called. (This screen prompts you for both the server's IP address and name.)

2.
Assign ns.my-web-site.org to handle your domain. This screen will prompt you for the server name only.

Sometimes, the registrar requires at least two registered name servers per domain. If you only have one, then you could either create a second name server record entry with the same IP address, but different name, or you could give your Web server a second IP address using an IP alias, create a second NAT entry on your firewall and then create the second name server record entry with the new IP address, and different name.

It normally takes about three to four days for your updated DNS information to be propagated to all 13 of the world's root name servers. You'll therefore have to wait about this amount of time before starting to notice people hitting your new Web site.

You can use the chapter's troubleshooting section to test specific DNS servers for the information they have on your site. You'll most likely want to test your new DNS server, which should be up to date, plus a few well-known ones, which should have delayed values.