搭建环境说明:
操作系统:fedora12
ip地址:192.168.40.83
pc上搭建dns服务器,实现通过域名www.swz.cnfedora.swz.cn均可以访问到pc
 
 
1.查看系统上是否安装了dns服务器软件

[root@localhost ~]# rpm -qa |grep bind
bind-utils-9.6.2-5.P2.fc12.i686
samba-winbind-clients-3.4.2-47.fc12.i686
bind-libs-9.6.2-5.P2.fc12.i686
bind-chroot-9.6.2-5.P2.fc12.i686
PackageKit-device-rebind-0.5.4-0.1.20091029git.fc12.i686
bind-devel-9.6.2-5.P2.fc12.i686
bindfs-1.8.3-3.fc12.i686
bind-sdb-9.6.2-5.P2.fc12.i686
ypbind-1.20.4-20.fc12.i686
bind-dyndb-ldap-0.1.0-0.5.a1.fc12.i686
bind-9.6.2-5.P2.fc12.i686
rpcbind-0.2.0-4.fc12.i686
bind-to-tinydns-0.4.3-6.fc12.i686
 

 
若显示上述信息则系统已经安装了dns软件,若无则执行命令进行安装

[root@localhost ~]# yum install bind*
 

 
2.dns服务器的主要配置文件所存放的目录
 a:主配置文件 /etc/named.conf
 b:正向解析文件和反向解析文件位置 /var/named/named.localhost /var/named/named.loopback
 
3.修改dns服务器的主配置文件

[root@localhost ~]# vim /etc/named.conf
添加的内容如下
zone "swz.cn." IN {
       type master;
       file "swz.cn.zone";//正向解析(域名-->ip地址)文件的名字,名字任意取
       allow-update { none;};
};
 
zone "40.168.192.in-addr.arpa." IN {
       type master;
       file "192.168.40.zone";//反向解析(ip地址--->域名)文件的名字,名字任意取
       allow-update { none;};
};
 

 
 
4.切换到正反向解析文件的目录

[root@localhost ~]# cd /var/named/
[root@localhost named]# cp named.localhost swz.cn.zone //named.localhost作为正向解析文件的模板,文件的名字同主配置文件中正向解析文件的名字
[root@localhost named]# cp named.localhost 192.168.40.zone //named.loopback作为反向解析文件的模板,文件的名字同配置文件中反向解析文件的名字
 

 
 
5.编辑正向解析文件(操作目录/var/named/swz.cn.zone)

[root@localhost named]# vim swz.cn.zone
修改的内容如下
$TTL 1D
@    IN SOA www.swz.cn. root.www.swz.cn. (
                                   0     ; serial
                                   1D   ; refresh
                                   1H   ; retry
                                   1W ; expire
                                   3H ) ; minimum
       NS   192.168.40.83
www       IN   A     192.168.40.83 //swz.cn域里的主机名1==>www.swz.cn
fedora     IN   A     192.168.40.83 //swz.cn域里的主机名2==>fedora.swz.cn
 

 
 
6.编辑反向解析文件(操作目录/var/named/192.168.40.zone)

[root@localhost named]# vim 192.168.40.zone
修改的内容如下
$TTL 1D
@    IN SOA www.swz.cn. root.www.swz.cn. (
                                   0     ; serial
                                   1D   ; refresh
                                   1H   ; retry
                                   1W ; expire
                                   3H ) ; minimum
       NS   192.168.40.83
83    IN   PTR fedora.swz.cn. //83pcip地址的最后一位
83    IN   PTR www.swz.cn. //83pcip地址的最后一位
 

 
 
7.修改正反向解析文件的访问权限(操作目录 /var/named/)

[root@localhost named]# chmod 777 swz.cn.zone
[root@localhost named]# chmod 777 192.168.40.zone
 

 
 
8. 配置域名信息

[root@localhost named]# vim /etc/resolv.conf
修改内容如下
# Generated by NetworkManager
#nameserver 61.128.128.68
nameserver 192.168.40.83 //添加的部分本机的ip地址
nameserver 61.154.22.41  
 

 
 
9.修改防火墙配置,允许DNS

[root@localhost named]# setup   --进入图形界面设置,在防火墙规则里允许dns
 

 
 
10.修改完配置文件之后需要重启服务使配置生效

[root@localhost named]# service named restart
 

 
 
11.验证配置是否生效

[root@localhost named]# nslookup --使用nslooku工具进行验证
> www.swz.cn
Server:           192.168.40.83
Address: 192.168.40.83#53
 
Name:     www.swz.cn
Address: 192.168.40.83
> fedora.swz.cn
Server:           192.168.40.83
Address: 192.168.40.83#53
 
Name:     fedora.swz.cn
Address: 192.168.40.83
> 192.168.40.83
Server:           192.168.40.83
Address: 192.168.40.83#53
 
83.40.168.192.in-addr.arpa    name = www.swz.cn.
83.40.168.192.in-addr.arpa    name = fedora.swz.cn.
>
 

 
 
说明:1、在提示符输入刚才配置主机名能正确的被解析则说明配置正确
      2、若无法重启服务可以通过查看系统的log信息来对问题进行定位分析
例:

[root@localhost named]# service named restart
停止 named                                               [确定]
启动 named                                               [确定]
[root@localhost named]# tail /var/log/messages
Nov 25 10:50:46 localhost named-sdb[4351]: zone 40.168.192.in-addr.arpa/IN: loaded serial 0
Nov 25 10:50:46 localhost named-sdb[4351]: zone 1.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.arpa/IN: NS '1.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.arpa' has no address records (A or AAAA)
Nov 25 10:50:46 localhost named-sdb[4351]: zone 1.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.arpa/IN: loaded serial 0
Nov 25 10:50:46 localhost named-sdb[4351]: zone swz.cn/IN: NS '192.168.40.83.swz.cn' has no address records (A or AAAA)
Nov 25 10:50:46 localhost named-sdb[4351]: zone swz.cn/IN: loaded serial 0
Nov 25 10:50:46 localhost named-sdb[4351]: zone localhost.localdomain/IN: loaded serial 0
Nov 25 10:50:46 localhost named-sdb[4351]: zone localhost/IN: loaded serial 0
Nov 25 10:50:46 localhost named-sdb[4351]: running
Nov 25 10:50:46 localhost named-sdb[4351]: zone swz.cn/IN: sending notifies (serial 0)
Nov 25 10:50:46 localhost named-sdb[4351]: zone 40.168.192.in-addr.arpa/IN: sending notifies (serial 0)
[root@localhost named]#