1、安装bind服务器软件及相关组件
查看系统中是否安装bind域名服务相关的几个软件包:
rpm -qa | grep bind
##############################################################################
bind-utils-9.3.6-4.P1.el5 提供DNS服务器的测试工具程序(nslookup、dig等)
bind-chroot-9.3.6-4.P1.el5 实现bind根目录的监牢机制,增强安全性
bind-libs-9.3.6-4.P1.el5 bind软件程序所需要的lib库文件
bind-9.3.6-4.P1.el5  提供了域名服务的主要程序和相关文件
##############################################################################
caching-nameserver-9.3.6-4.P1.el5.i386.rpm 配置bind作为缓存域名服务器提供的必要的默认配置文件
(这个包默认情况下多数系统没有安装,需要手动安装)
mount /dev/cdrom /media/
rpm -ivh /media/Server/caching-nameserver-9.3.6-4.P1.el5.i386.rpm

2、查看安装的目录和文件
   rpm -ql bind
   rpm -ql bind-chroot
   rpm -ql bind-utils
   rpm -ql caching-nameserver

/usr/sbin/named   域名服务器的守护进程
/var/run/named/named.pid DNS的PID文件
/etc/sysconfig/named
/etc/rc.d/init.d/named
/etc/logrotate.d/named   这3个脚本用于管理域名服务器守护进程
/usr/bin/dig
/usr/bin/host
/usr/bin/nslookup  这3个程序用于对DNS服务器进行测试
/var/named/chroot  安装了bind-chroot软件包后,bind根目录真实位置
/var/named/chroot/etc  DNS服务器的配置文件存放目录
/var/named/chroot/var  DNS服务器的区域数据文件存放目录
/usr/sbin/named-bootconf 域名服务器的启动配置脚本
/usr/sbin/named-checkconf 域名服务器的主配置文件语法检验程序
/usr/sbin/named-checkzone 域名服务器的区域配置文件检验程序
/usr/sbin/dns-keygen  DNS加密密钥生成程序
/usr/sbin/dnssec-keygen  DNSSEC
/usr/sbin/dnssec-signzone 加密密钥生成程序
/usr/sbin/rndc   域名服务器的控制程序,可以使用rndc.conf文件加载相关配置
/usr/sbin/lwresd  轻量级的解析服务器,可以作为缓冲域名服务器
/usr/share/doc/bind-9.3.6/sample/etc/named.conf  手工建立named.conf配置文件的模板文件

3、默认情况下主配置文件named.conf不存在,通过模板文件生成主配置文件
cp -p /usr/share/doc/bind-9.3.6/sample/etc/named.conf /var/named/chroot/etc/named.conf
不过由于这里的模板文件配置参数较多,我们大部分基本不用,所以建议直接编辑这个文件如下:(供参考)
options
{
        listen-on port 53 { 192.168.1.102; };
        directory "/var/named";
        dump-file               "/var/named/data/cache_dump.db";
        statistics-file         "/var/named/data/named_stats.txt";
        memstatistics-file      "/var/named/data/named_mem_stats.txt";
        allow-query { 192.168.1.0/24; };
        recursion yes;

};

################################分割线 构建缓存域名服务器###########################
(缓存域名服务器的验证需要连接Internet环境)
(1) 构建缓存域名服务器,修改named.conf
方法一:定义根
vi /var/named/chroot/etc/named.conf
options
{
        listen-on port 53 { 192.168.1.102; };
        directory "/var/named";
        dump-file               "/var/named/data/cache_dump.db";
        statistics-file         "/var/named/data/named_stats.txt";
        memstatistics-file      "/var/named/data/named_mem_stats.txt";
        allow-query { 192.168.1.0/24; };
        recursion yes;
};
zone "." IN {
        type hint;
        file "named.ca";
};

方法二:定义转发器
vi /var/named/chroot/etc/named.conf
options
{
        listen-on port 53 { 192.168.1.102; };
        directory "/var/named";
        dump-file               "/var/named/data/cache_dump.db";
        statistics-file         "/var/named/data/named_stats.txt";
        memstatistics-file      "/var/named/data/named_mem_stats.txt";
        allow-query { 192.168.1.0/24; };
        recursion yes;
        forwarders { 218.30.19.50; 61.134.1.5; };
};
在现实应用中,建议采用方法二,为了提高解析效率,可以不向根域查询,而是将客户端的解析请求转发给特定的DNS服务器,收到返回的查询结果后再传递给客户端。

################################分割线 构建主域名服务器###########################
(1) 确定DNS服务器与需要解析的主机名和IP地址
DNS服务器:server01.benet.com-->192.168.1.102
www服务器:www.benet.com-->192.168.1.102
邮件服务器:mail.benet.com-->192.168.1.105
主域服务器:ns1.benet.com-->192.168.1.102
从域服务器:ns2.benet.com-->192.168.1.103
(2) 创建正向区域和反向区域
vi /var/named/chroot/etc/named.conf
options
{
        listen-on port 53 { 192.168.1.102; };
        directory "/var/named";
        dump-file               "/var/named/data/cache_dump.db";
        statistics-file         "/var/named/data/named_stats.txt";
        memstatistics-file      "/var/named/data/named_mem_stats.txt";
        allow-query { 192.168.1.0/24; };
        recursion yes;
};
zone "benet.com" IN {
        type master;
        file "benet.zx";
};
zone "1.168.192.in-addr.arpa" IN {
        type master;
        file "benet.fx";
};

(3) 创建正向和反向区域文件
通过参考localhost域的正反向区域文件创建区域文件
cd /var/named/chroot/var/named
cp -p localdomain.zone benet.zx
cp -p named.local benet.fx

vi benet.zx
$TTL    86400
@               IN SOA  benet.com. root.benet.com. (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
                IN NS           ns1.benet.com.
ns1     IN A            192.168.1.102
www     IN A            192.168.1.102
server01        IN A    192.168.1.102
mail    IN A            192.168.1.105
@       IN MX  10         mail.benet.com.
ns2     IN A            192.168.1.103

vi benet.fx
$TTL    86400
@       IN      SOA     benet.com. root.benet.com.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
        IN      NS      ns1.benet.com.
102     IN      PTR     ns1.benet.com.
102     IN      PTR     www.benet.com.
102     IN      PTR     server01.benet.com.
105     IN      PTR     mail.benet.com.
103     IN      PTR     ns2.benet.com.

(4) 重新启动named服务
service named restart
(5) 配置客户端测试
nslookup


################################分割线 构建从域名服务器###########################
(1) 假设从域名服务器的IP地址为192.168.1.103
主机名为:ns2.benet.com
(2) 在从域名服务器上创建主配置文件
vi /var/named/chroot/etc/named.conf
options
{
        listen-on port 53 { 192.168.1.103; };
        directory "/var/named";
        dump-file               "/var/named/data/cache_dump.db";
        statistics-file         "/var/named/data/named_stats.txt";
        memstatistics-file      "/var/named/data/named_mem_stats.txt";
        allow-query { 192.168.1.0/24; };
        recursion yes;
};
zone "benet.com" IN {
        type slave;
 masters { 192.168.1.102; };
        file "benet.zx";
};
zone "1.168.192.in-addr.arpa" IN {
        type slave;
 masters { 192.168.1.102; };
        file "benet.fx";
};
(3) 在主域名服务器上修改主配置文件为:
vi /var/named/chroot/etc/named.conf
options
{
        listen-on port 53 { 192.168.1.102; };
        directory "/var/named";
        dump-file               "/var/named/data/cache_dump.db";
        statistics-file         "/var/named/data/named_stats.txt";
        memstatistics-file      "/var/named/data/named_mem_stats.txt";
        allow-query { 192.168.1.0/24; };
        recursion yes;
};
zone "benet.com" IN {
        type master;
        file "benet.zx";
 allow-transfer { 192.168.1.103; };
};
zone "1.168.192.in-addr.arpa" IN {
        type master;
        file "benet.fx";
 allow-transfer { 192.168.1.103; };
};
(4) 在从域名服务器上启动named服务或重启
server named start
(5) 可以查看日志
tail /var/log/messages
(6) 重新配置客户端测试从域名服务器


################################分割线 构建分离解析的域名服务器###########################
(1) 根据实验要求,搭建实验环境
(2) 修改主配置文件,创建视图和区域
vi /var/named/chroot/etc/named.conf
options
{
        listen-on port 53 { 192.168.1.102; 202.100.100.1; };
        directory "/var/named";
        dump-file               "/var/named/data/cache_dump.db";
        statistics-file         "/var/named/data/named_stats.txt";
        memstatistics-file      "/var/named/data/named_mem_stats.txt";
        allow-query { any; };
        recursion yes;
};
view "lan" {
        match-clients { 192.168.1.0/24; };
        zone "benet.com" IN {
        type master;
        file "benet.zx";
   };
};
view "wan" {
        match-clients { any; };
        zone "benet.com" IN {
        type master;
        file "benet.wan";
   };
};
(3) 分别建立对内、对外解析的区域数据库文件
cp -p localdomain.zone benet.zx
cp -p benet.zx benet.wan

vi /var/named/chroot/var/named/benet.zx
$TTL    86400
@               IN SOA  benet.com. root.benet.com. (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
                IN NS           ns1.benet.com.
ns1     IN A            192.168.1.102
www     IN A            192.168.1.102

vi /var/named/chroot/var/named/benet.wan
$TTL    86400
@               IN SOA  benet.com. root.benet.com. (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
                IN NS           ns1.benet.com.
ns1     IN A            202.100.100.1
www     IN A            202.100.100.1

(4) 重新启动named服务
service named restart
(5) 验证分离解析域名服务器
分别在内、外网络的客户端主机中进行域名解析验证,对于同一域名www.benet.com
内网客户端:
nslookup
> www.benet.com
Server:         192.168.1.102
Address:        192.168.1.102#53

Name:   www.benet.com
Address: 192.168.1.102

外网客户端:
nslookup
> www.benet.com
Server:         202.100.100.1
Address:        202.100.100.1#53

Name:   www.benet.com
Address: 202.100.100.1