debian bind dns配置入门
2013-06-28 17:24:50 阿炯

本站赞助商链接,请多关照。 安装最新稳定版本(目前是9.8系)
# apt-get -t squeeze-backports install bind9 bind9utils

debian将bind的配置文件分的较细,在其主配置文件named.conf使用'include'指令来包含所有的配置。

这是以'freeoa.net'域名为例,添加一个域配置来做测试。在named.conf文件加入:
include "/etc/bind/named.conf.freeoa";

Freeoa.net的配置
#正向库
zone "freeoa.net" {
 type master;
 file "/etc/bind/db/pos.freeoa";
};

#反向库
zone "18.168.192.in-addr.arpa" {
 type master;
 file "/etc/bind/db/rev.freeoa";
};

先来看下正向库文件的格式及写法:
;
$TTL    604800
@       IN      SOA     pridns.freeoa.net. dnsadmin.freeoa.net. (
                           2            ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      pridns.freeoa.net.
@       IN      MX      10      mail.freeoa.net.
@       IN      A       127.0.0.1

pridns  IN      A       192.168.18.100
master  IN      A       192.168.18.98
vmxp    IN      A       192.168.18.99
www     IN      A       192.151.240.19
mail    IN      A       192.168.18.100
ftp     IN      CNAME   master.freeoa.net.

相关配置指令说明:

a quick review of some lines from the above bind DNS zone file:


SOA Record: nameserver authoritative for a zone linuxconfig.org is ns1.linuxconfig.org and admin.linuxconfig.org is an email address of a person responsible for this DNS zone.

NS Records: two nameservers for a linuxconfig.org zone are ns[1,2].linuxconfig.org

MX ( Mail Exchange): linuxconfig.org mail exachange record. Number 10 means a preference for discarting a records A : A simply means address inanother words in linuxconfig.org's zone a ns1 would ahve a A ( address ) 192.168.0.10.

CNAME Record ( Canonical Name record ): restart the query using the canonical name instead of the original name

反解库的格式及写法:
;
$TTL    604800
@    IN    SOA    pridns.freeoa.net. dnsadmin.freeoa.net. (
                  1        ; Serial
             604800        ; Refresh
              86400        ; Retry
            2419200        ; Expire
             604800 )    ; Negative Cache TTL
;
@    IN    NS    pridns.freeoa.net.

100    IN    PTR    pridns.freeoa.net.
99    IN    PTR    vmxp.freeoa.net.
98    IN    PTR    master.freeoa.net.
100    IN    PTR    mail.freeoa.net.

PTR: a NDS record used for a mapping of an IP address to a host name.

---------------
配置检查

注意,这里所说的配置并不是指运行程序所用的配置文件,而是指域名的配置文件,比如像上面所提及的'pos.freeoa'与'rev.freeoa'。当然也有专门针对主配置文件的检查工具,下面将会介绍。这需要安装bind的工具包:bind9utils,另外还有一款dns通用的工具包:dnsutils,它包含了dig、nslookup等常用调试工具。

named-checkzone utility

named-checkzone example.com /etc/bind/db.example.com
反解检查
named-checkzone 1.168.192.in-addr.arpa. /etc/bind/db.192

主配置文件检查
# named-checkconf /etc/bind/named.conf

在上面的检查无误后,重置或重启bind使设置生效,除了系统的控制脚本外,还可以用'rndc reload'来重置bind服。

域名配置查询测试
用于对服务器上权威的域名进行查询检查。这就需要借助于相关的工具了,主要有两个工具可用:dig和nslookup。后者在windows、linux平台上都可用,但前者用Perl写成,在使用更灵活一些。
dig @192.168.18.100 www.freeoa.net
使用'192.168.18.100'作为我的dns服务器,来查询'www.freeoa.net'所指的解析地址。

dig @192.168.18.100 -x 192.168.18.98
使用'192.168.18.100'作为我的dns服务器,来反查'192.168.18.98'所对应的主机名。

---------------
查询转发

上面的设置可以让仅使用该dns作为解析的客户端查询到该dns服务器的域名信息,前提是该服务器没有针对性ip查询限制。但不能给客户端其它非该服务器上的域名信息,通过对bind的配置,可让它代客户端查询其它域名的信息。

在named.conf.options配置文件中开启。
forwarders {
 8.8.8.8;
};

这样将会转发到google提供的dns服务器上,查询后在返回给客户端。

参考来源:

BIND9ServerHowto