System Administration Guide: Naming and Directory Services (DNS, NIS, and LDAP)

Configuring a Network For DNS

To configure a network for DNS, you must set up a client and a server.

How to Set Up a DNS Client

Set up the clients prior to setting up the DNS server.

  1. Become superuser.

  2. Create the /etc/resolv.conf file.

    A simple example resolv.conf file for a client (non-server) machine in the doc.com domain is shown below.


    Example 4–2 Sample resolv.conf File


    ; Sample resolv.conf file for the machine polaris
    domain doc.com
    ; try local name server
    nameserver 127.0.0.1
    ; if local name server down, try these servers
    nameserver 2000::16:a:a00:20ff:de8a:643a
    nameserver 192.168.16.7
    ; sort the addresses returned by gethostbyname(3c)
    sortlist
    130.155.160.0/255.255.240.0
    130.155.0.0

    The first line of the /etc/resolv.conf file lists the domain name in the following form.


    domain domainname
    

    Where domainname is the name that is registered with InterNIC.


    Note –

    No spaces or tabs are permitted at the end of the domain name. Make sure that you enter a hard carriage return immediately after the last character of the domain name.


    The second line identifies the name server in the form


    nameserver 127.0.0.1

    The next lines list the IP addresses of up to three DNS master, slave, or cache-only name servers that the resolver should consult to resolve queries. Do not list more than three servers, master or slave. Name server entries have the following form.


    nameserver IP_address
    

    IP_address is the IP address of a master or slave DNS name server. IP_address can be either an IPv4 or an IPv6 address. The resolver queries these name servers in order until the resolver obtains the information it needs.

    The fifth line of the /etc/resolv.conf file lists the address sortlist in the form:


    sortlist
    addresslist
    

    addresslist specifies the sort order of the addresses returned by gethostbyname(). In our example, gethostbyname returns the netmask pair 130.155.160.0/255.255.240.0 ahead of the IP address 130.155.0.0.

  3. Modify the /etc/nsswitch.conf file.

    NIS. If your master enterprise-level naming service is NIS, with proper configuration, NIS is already DNS-enabled.

    Files-based. If your master enterprise-level naming service is based on /etc files, or if your master enterprise-level naming service is NIS+, do the following.

    1. Open the /etc/nsswitch.conf file.

    2. DNS can be the only source or an additional source for the hosts information. Locate the hosts line and use DNS as shown below.


      hosts: files dns

      or


      hosts: nis dns [NOTFOUND=return] files

      or


      hosts: dns nis [NOTFOUND=return] files

      Do not use the above syntax for NIS clients, or else the clients will search for unresolved names twice in DNS.

    3. Specify DNS as a source of hosts information.

    4. Save the file and reboot.

How to Set Up a DNS Server

  1. Become superuser.

  2. Set the server up as a DNS client, which would include setting up the server's resolv.conf file). See How to Set Up a DNS Client.

  3. Set up the configuration file. See Example Configuration Files.

  4. Set up the data files. You need to set up four data files.

    • named.ca

    • hosts

    • hosts.rev

    • named.local

  5. Initialize the server. See How to Initialize the Server.

  6. Test the server. See How to Test Your Installation.


    Note –

    The most common use of DNS is to connect your network to the Internet. To connect to the Internet, your network IP address must be registered with whomever is administering your parent domain. Who that administrator is varies according to your geographic location and the type of parent domain. This manual does not describe how to register networks with domain administrators.


How to Specify a Master Server

The two types of master server are as follows.

To specify a server as the master server for a given zone, add the following statements in that server's named.conf file.

  1. Create a directory for the zone files.

    The following line tells the DNS name server to look for the zone data files in the specified directory. It is recommended that the directory be owned by root and have 0700 permissions. It is also recommended that the directory be on a file system that is accessible to the name server when it starts up.


    options {
    	      directory "/var/named";
    };

    Statements in the options section are globally applicable configuration options and defaults for the name server. See the named.conf(4) man page for further details.

  2. Create the master record for the zone.

    The following lines designate the DNS name server as a master server for the zone. The zone definition begins with the keyword zone followed, in order, by the domain and the class. “in” denotes the Internet class and can be omitted as it is the default. The record also tells the server where to find the SOA record (Start of Authority) that makes the server authoritative for the zone. The file "db.doc.sun.com" should be in the directory specified in the options statement.


    zone "doc.sun.com"     in     {
           type master;
           file "db.doc.sun.com";
    };
  3. Create a master record for the zone's reverse maps.

    The following lines designate the server as a master server for the zone's reverse address map. The reverse address zone contains the zone's IP address in reverse order followed by in-addr.arpa. For example, assuming doc.sun.com zone's IP address is 10.0.0, the reverse address zone would be 0.0.10.in-addr-arpa.


    zone "0.0.10.in-addr.arpa"   in   {
            type master;
            file "db.10.0.0";
    };
  4. Create a master record for the local loopback interface.

    The following lines designate the server as a master server for the loopback interface.


    Note –

    Loopback hosts are always identified as 0.0.127.in-addr.arpa.


    Thus, the following line in a configuration file specifies that the server is the master server for the reverse address domain of the loopback host using authoritative data from the file named.local.


    zone "0.0.127.in-addr.arpa"   in   {
            type master;
            file "db.127.0.0";
    };
  5. Create a “root hints” file.


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

    The file named.ca contains the location of the name servers for the root zone. For the doc.sun.com zone above, it would be the name servers for the sun.com domain.

How to Specify a Slave Server

A slave server maintains a copy of the data for the zone. The master server sends its data and delegates authority to the slave server. Clients can query a slave server for DNS information. By using slave servers, you can improve response time by spreading the load over multiple machines. Slave servers also provide backup when the master server crashes.

When in.named starts, the daemon requests all the data for the given zone from the master. The slave server then periodically checks with the master to see if the master needs to update its database. The process of sending the most recent zone database from the master to the slave is called a zone transfer. Therefore, you do not modify data files on a slave server. You modify the data files on the zone's master server. The slave servers then update their files from the master.

To specify that a server is to be the slave server for a given zone, you create slave records in that server's named.conf file. Separate records can designate the server as a slave server for the zone, the zone's reverse address domain, and the loopback host. A slave zone definition has a similar format as the master zone definition. The type is changed to slave and a line with the keyword masters along with the IP address(es) of the master server(s) is added.

For example, the following lines in a configuration file specify that the server is the slave server for the doc.sun.com zone and its reverse address domain. The lines also specify that the slave server obtains its authoritative data from the master server at 172.16.0.1 and initially loads its data from the file tmp.db.doc.sun.com:


zone "doc.sun.com"   in   {
       type slave;
       file "tmp.db.doc.sun.com";
       masters { 172.16.0.1; };
};

Note –

A server can act as the master server for one or more zones, and as the slave server for one or more zones. The mixture of entries in the configuration file determines whether a server is a master or slave server for a given zone.


How to Specify a Cache-Only or Stub Server

All servers are caching servers as all servers maintain a cache of DNS data. A cache-only or stub server is a server that is not a master server for any zone other than the reverse loopback zone in the in-addr.arpa. domain.

A cache-only server handles queries but does not maintain any authoritative data. The cache-only server handles queries by asking the hosts that are listed in the named.ca file for the needed information.

The following is a sample configuration file for a cache-only server. Note that the class (in) has been omitted as it is the default


Example 4–3 Sample Master Configuration File for Caching-Only Server


;
; Sample named.conf file for caching only name server
;

options {
        directory "/var/named";
};

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

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