7.2. 域名服务器 (DNS) 配置与管理

在我的工作场所,我们使用 Linux 作为 DNS 服务器。它的性能非常出色。本节将介绍如何使用 Red Hat 发行版标配的 BIND 8.x 软件包配置这些服务的 DNS 表。

注意:注意:Red Hat 5.1 及更早版本使用 BIND 4.x 软件包,其配置文件格式略有不同。BIND 8.x 比 BIND 4.x 提供了更多的功能,并且由于 4.x 已停止开发,您应该考虑将您的 BIND 软件包升级到最新版本。只需安装 BIND RPM 软件包(有关使用 RPM 实用程序的详细信息,请参阅第 10.1 节),然后将您的配置文件转换为新格式。

幸运的是,将您现有的 BIND 4.x 配置文件转换为与 BIND 8.x 兼容非常容易!在 BIND 提供的文档目录中(例如,``/usr/doc/bind-8.1.2/'' 对于 BIND 版本 8.1.2),存在一个名为 ``named-bootconf.pl'' 的文件,这是一个可执行的 Perl 程序。假设您的系统上安装了 Perl,您可以使用此程序转换您的配置文件。要执行此操作,请键入以下命令(以 root 用户身份)

cd /usr/doc/bind-8.1.2
./named-bootconf.pl < /etc/named.boot > /etc/named.conf
mv /etc/named.boot /etc/named.boot-obsolete

您现在应该有一个 ``/etc/named.conf'' 文件,该文件应该可以与 BIND 8.x "开箱即用"。您现有的 DNS 表将与新版本的 BIND 一起按原样工作,因为表的格式保持不变。

在 Linux 下配置 DNS 服务包括以下步骤

  1. 要启用 DNS 服务,``/etc/host.conf'' 文件应如下所示

    # Lookup names via /etc/hosts first, then by DNS query
    order hosts, bind
    # We don't have machines with multiple addresses
    multi on
    # Check for IP address spoofing
    nospoof on
    # Warn us if someone attempts to spoof
    alert on

    额外的欺骗检测会给 DNS 查找增加一点性能损失(虽然可以忽略不计),所以如果您不太担心这一点,您可能希望禁用 "nospool""alert" 条目。

  2. 根据需要配置 ``/etc/hosts'' 文件。通常这里不需要太多内容,但为了提高性能,您可以添加您经常访问的任何主机(例如本地服务器),以避免对它们执行 DNS 查找。

  3. ``/etc/named.conf'' 文件应配置为指向您的 DNS 表,如下例所示。

    注意:(注意:显示的 IP 地址仅为示例,必须替换为您自己的类地址!)

    options {
    	// DNS tables are located in the /var/named directory
    	directory "/var/named";
    
    	// Forward any unresolved requests to our ISP's name server
    	// (this is an example IP address only -- do not use!)
    	forwarders {
    		123.12.40.17;
    	};
    
    	/*
    	 * If there is a firewall between you and nameservers you want
    	 * to talk to, you might need to uncomment the query-source
    	 * directive below.  Previous versions of BIND always asked
    	 * questions using port 53, but BIND 8.1 uses an unprivileged
    	 * port by default.
    	 */
    	// query-source address * port 53;
    };
    
    // Enable caching and load root server info
    zone "named.root" {
    	type hint;
    	file "";
    };
    
    // All our DNS information is stored in /var/named/mydomain_name.db
    // (eg. if mydomain.name = foobar.com then use foobar_com.db)
    zone "mydomain.name" {
    	type master;
    	file "mydomain_name.db";
    	allow-transfer { 123.12.41.40; };
    };
    
    // Reverse lookups for 123.12.41.*, .42.*, .43.*, .44.* class C's
    // (these are example Class C's only -- do not use!)
    zone "12.123.IN-ADDR.ARPA" {
    	type master;
    	file "123_12.rev";
    	allow-transfer { 123.12.41.40; };
    };
    
    // Reverse lookups for 126.27.18.*, .19.*, .20.* class C's
    // (these are example Class C's only -- do not use!)
    zone "27.126.IN-ADDR.ARPA" {
    	type master;
    	file "126_27.rev";
    	allow-transfer { 123.12.41.40; };
    };

    提示:提示:请注意allow-transfer上面的选项,它将 DNS 区域传送限制为给定的 IP 地址。在我们的示例中,我们允许位于 123.12.41.40 的主机(可能是我们域中的辅助 DNS 服务器)请求区域传送。如果您省略此选项,互联网上的任何人都可以请求此类传送。由于所提供的信息通常被垃圾邮件发送者和 IP 欺骗者使用,我强烈建议您限制区域传送,除非您的辅助 DNS 服务器,或使用环回地址 ``127.0.0.1'' 代替。

  4. 现在您可以在 ``var/named/'' 目录中设置您的 DNS 表,如步骤三中的 ``/etc/named.conf'' 文件中配置的那样。首次配置 DNS 数据库文件是一项重大任务,超出了本文档的范围。有几个在线和印刷形式的指南应该参考。但是,下面提供了一些示例。

    ``/var/named/mydomain_name.db'' 正向查找文件中的示例条目

    ; This is the Start of Authority (SOA) record.  Contains contact
    ; & other information about the name server.  The serial number
    ; must be changed whenever the file is updated (to inform secondary
    ; servers that zone information has changed).
        @ IN SOA mydomain.name.  postmaster.mydomain.name. (
    	19990811	; Serial number
    	3600		; 1 hour refresh
    	300		; 5 minutes retry
    	172800		; 2 days expiry
    	43200 )		; 12 hours minimum
    
    ; List the name servers in use.  Unresolved (entries in other zones)
    ; will go to our ISP's name server isp.domain.name.com
    	IN NS		mydomain.name.
    	IN NS		isp.domain.name.com.
    
    ; This is the mail-exchanger.  You can list more than one (if
    ; applicable), with the integer field indicating priority (lowest
    ; being a higher priority)
    	IN MX		mail.mydomain.name.
    
    ; Provides optional information on the machine type & operating system
    ; used for the server
    	IN HINFO	Pentium/350	LINUX
    
    ; A list of machine names & addresses
        spock.mydomain.name.    IN A    123.12.41.40   ; OpenVMS Alpha
        mail.mydomain.name.     IN A    123.12.41.41   ; Linux (main server)
        kirk.mydomain.name.     IN A    123.12.41.42   ; Windows NT (blech!)
    
    ; Including any in our other class C's
        twixel.mydomain.name.   IN A    126.27.18.161  ; Linux test machine
        foxone.mydomain.name.   IN A    126.27.18.162  ; Linux devel. kernel
    
    ; Alias (canonical) names
        gopher	IN CNAME	mail.mydomain.name.
        ftp		IN CNAME	mail.mydomain.name.
        www		IN CNAME	mail.mydomain.name.

    ``/var/named/123_12.rev'' 反向查找文件

    ; This is the Start of Authority record.  Same as in forward lookup table.
        @ IN SOA mydomain.name.  postmaster.mydomain.name. (
    	19990811	; Serial number
    	3600		; 1 hour refresh
    	300		; 5 minutes retry
    	172800		; 2 days expiry
    	43200 )		; 12 hours minimum
    
    ; Name servers listed as in forward lookup table
    	IN NS		mail.mydomain.name.
    	IN NS		isp.domain.name.com.
    
    ; A list of machine names & addresses, in reverse.  We are mapping
    ; more than one class C here, so we need to list the class B portion
    ; as well.
        40.41	IN PTR    spock.mydomain.name.
        41.41	IN PTR    mail.mydomain.name.
        42.41	IN PTR    kirk.mydomain.name.
    
    ; As you can see, we can map our other class C's as long as they are
    ; under the 123.12.* class B addresses
        24.42	IN PTR    tsingtao.mydomain.name.
        250.42	IN PTR    redstripe.mydomain.name.
        24.43	IN PTR    kirin.mydomain.name.
        66.44	IN PTR    sapporo.mydomain.name.
    
    ; No alias (canonical) names should be listed in the reverse lookup
    ; file (for obvious reasons).

    可能需要创建任何其他反向查找文件以映射不同 B 类中的地址(例如 126.27.*),并且看起来与上面的示例反向查找文件非常相似。

  5. 确保 named 守护进程正在运行。此守护进程通常在系统启动时从 ``/etc/rc.d/init.d/named'' 文件启动。您也可以手动启动和停止守护进程;键入 ``named start'' 和 ``named stop'',分别。

  6. 每当对 DNS 表进行更改时,应通过键入 ``/etc/rc.d/init.d/named restart'' 重新启动 DNS 服务器。然后,您可能希望使用诸如 "nslookup" 之类的工具查询您添加或更改的机器,以测试您的更改。

有关配置 DNS 服务的更多信息,请参见 ``DNS-HOWTO'' 指南,网址为 http://metalab.unc.edu/Linux/HOWTO/DNS-HOWTO-5.html