配置环境。一台linux系统服务器,Red  Hat 企业版5 一张Red  Hat 企业版5光盘(提前插到光驱中等下要挂载东西)
 
#!/bin/bash
mkdir /mafei
mount /dev/cdrom /mafei
cd /mafei/Server
rpm -e `rpm -qa | grep ^bind` --nodeps --force
rpm  -ivh bind-* --nodeps --force
rpm -ivh caching-nameserver-9.3.3-7.el5.i386.rpm
echo "search server.mafei.com" > /etc/resolv.conf
echo "nameserver 192.168.142.128" >> /etc/resolv.conf
cd /var/named/chroot/etc/
vi /var/named/chroot/etc/named.caching-nameserver.conf  << MAFEI
 
:%s/127.0.0.1/any/g
 
:%s/localhost/any/g
 
:wq
MAFEI
echo 'zone "mafei.com" IN { type master; file "mafei.com"; };' >> /var/named/chroot/etc/named.rfc1912.zones
cd /var/named/chroot/var/named/
cp named.local mafei.com
vi /var/named/chroot/var/named/mafei.com    << MAFEIFEI
 
:%s/1       IN      PTR     localhost./www       IN      A     192.168.142.128/g
:wq
MAFEIFEI
bind-chroot-admin -s
service named restart
ping www.mafei.com
如果想一步步做的话下面可供参考。具体有正向解析,反向解析,以及不同域名同一IP等的配置实例,首先做一个正向,如果正向都没做出来那么后面的也不用做了。
 
配置IP子网掩码。以及DNS
 
[root@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
HWADDR=00:0c:29:c1:ef:7f
ONBOOT=yes
IPADDR=192.168.142.2
NETMASK=255.255.255.0
TYPE=Ethernet
 
 
[root@server ~]# vi /etc/resolv.conf
search mafei.com
nameserver 192.168.142.2
 
将光盘挂载到/mafei下。并删除原来的DNS软件包
[root@server ~]# mkdir /mafei
[root@server ~]# mount /dev/cdrom /mafei
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@server ~]# cd /mafei/Server/
[root@server Server]# rpm -e `rpm -qa | grep ^bind` --nodeps
warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave
/var/tmp/rpm-tmp.51087: line 2: /usr/sbin/bind-chroot-admin: No such file or directory
error: %preun(bind-chroot-9.3.3-7.el5.i386) scriptlet failed, exit status 1
 
 
 
从光盘中安装DNS服务器必备的两大软件包
其中bind软件包是DNS服务器的配置软件包
至于caching软件包么。里面提供了DNS服务配置的模板你牛的话也可以不用自己写
[root@server Server]# rpm -ivh bind-* --nodeps --force
warning: bind-9.3.3-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
   1:bind-utils             ########################################### [ 14%]
   2:bind                   ########################################### [ 29%]
   3:bind-chroot            ########################################### [ 43%]
   4:bind-devel             ########################################### [ 57%]
   5:bind-libbind-devel     ########################################### [ 71%]
   6:bind-libs              ########################################### [ 86%]
   7:bind-sdb               ########################################### [100%]
[root@server Server]# rpm -ivh caching-nameserver-9.3.3-7.el5.i386.rpm
warning: caching-nameserver-9.3.3-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
   1:caching-nameserver     ########################################### [100%]
 
进入DNS主目录。修改主配置文件中选项。
其实说白了。就是将127.0.0.1该为any
localhost改为anyOK了。至于内容么。。应该知道吧。
[root@server Server]# hostname
server.mafei.com
[root@server Server]# cd /var/named/chroot/etc/
[root@server etc]# ls
localtime  named.caching-nameserver.conf  named.rfc1912.zones  rndc.key
[root@server etc]# vi named.caching-nameserver.conf
options {
        listen-on port 53 { any; };
        listen-on-v6 port 53 { ::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";
        query-source    port 53;
        query-source-v6 port 53;
        allow-query     { any; };
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
view any_resolver {
        match-clients      { any; };
        match-destinations { any; };
        recursion yes;
        include "/etc/named.rfc1912.zones";
};
 
 
修改DNS的辅配置文件在最后加入要建立的域名
本文中要建立的域名为mafei.com
注意: 在指定文件中的mafei.com虽然是自定义的文件名称但是必须和后面的文件名称相同否则会出错。而且注意每一行后面都有;的,(我就在这里栽过N次。。)
 
[root@server etc]# vi named.rfc1912.zones
 
zone "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 {
        type master;
        file "named.ip6.local";
        allow-update { none; };
};
 
zone "255.in-addr.arpa" IN {
        type master;
        file "named.broadcast";
        allow-update { none; };
};
 
zone "0.in-addr.arpa" IN {
        type master;
        file "named.zero";
        allow-update { none; };
};
zone "mafei.com" IN {
        type master;
        file "mafei.com";
};
 
 
不是要做www.mafei.com啊。刚才做了mafei.com现在来做下www(虽然叫起来不太专业但最起码能听懂、)
进入DNS的主机目录,这里有配置的模板我们只需要拷贝一份过来再进行修改就OK
 
此处我拷了一份模板过来名字为mafei.com (注意要和刚才的文件名要相同。)
在后面一行添加一条主机的A记录就行。让主机能够对应相应的IP
 
[root@server etc]# vi named.rfc1912.zones
[root@server etc]# cd ../var/named/
[root@server named]# ls
data              localhost.zone   named.ca         named.local  slaves
localdomain.zone  named.broadcast  named.ip6.local  named.zero
[root@server named]# cp named.local mafei.com
[root@server named]# vi mafei.com
$TTL    86400
@       IN      SOA     localhost. root.localhost.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
        IN      NS      localhost.
www     IN      A       192.168.142.2
 
因为做完之后各个文件的权限的问题所以得用Bind-chroot-admin –s 进行权限的自动化配置
做完之后重启下named 服务即可用了
 
[root@server named]# bind-chroot-admin –s
[root@server etc]# service named restart
Stopping named:                                            [FAILED]
Starting named:                                            [  OK  ]
[root@server etc]# ping www.mafei.com
PING www.mafei.com (192.168.142.2) 56(84) bytes of data.
64 bytes from 192.168.142.2: icmp_seq=1 ttl=64 time=0.027 ms
64 bytes from 192.168.142.2: icmp_seq=2 ttl=64 time=0.028 ms
64 bytes from 192.168.142.2: icmp_seq=3 ttl=64 time=0.030 ms
 
--- www.mafei.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.027/0.028/0.030/0.004 ms
 
 
 
 
至于做DNS的反向解析,以及同一IP不同主机,只要前面做好了。后面只需要。添加相应的域名记录和主机记录即可,,其实都有模板只要照着上面模板抄一遍就OK了。不用死记
1.      DNS的辅助主文件中添加域名记录。 (添加反向记录时输入的ip 为服务器ip地址的后3位)
此处添加192.168.142.2 解析为www.mafeifei.com
www.fei.com解析为192.168.142.2(同一ip不同域名,)
[root@server etc]# vi named.rfc1912.zones
zone "mafei.com" IN {
        type master;
        file "mafei.com";
};
zone "142.168.192.in-addr.arpa" IN {
        type master;
        file "mafeifei.com";
};
zone "fei.com" IN {
        type master;
        file "fei.com";
};
 
2.      设置主机记录。
设置同一ip不同域名时因为刚才做www.mafei.com时已经做过。此步还是要解析为www.fei.com 添加一条A记录即可。所以此处不再重复。直接复制一份。
 
设置反向域名解析时 还是cp模板到mafeifei.com 设置记录。格式为
2 此服务器ip192.168.142.2此处的2就是服务器的最后一位ip
PTR 设置主机的反向解析。
www.mafeifei.com 这个没什么说的就是要解析的域名
[root@server named]# cp mafei.com fei.com
[root@server named]# cp named.local mafeifei.com
 [root@server named]# vi mafeifei.com
$TTL    86400
@       IN      SOA     localhost. root.localhost.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
        IN      NS      localhost.
2       IN      PTR     www.mafeifei.com.
 
root@server named]# ls
data              localhost.zone  named.broadcast  named.local
fei.com           mafei.com       named.ca         named.zero
localdomain.zone  mafeifei.com    named.ip6.local  slaves
 
 
做完还是老动作先做权限再重启服务使配置生效
[root@server named]# bind-chroot-admin -s
[root@server named]# service named restart
Stopping named:                                            [  OK  ]
Starting named:                                            [  OK  ]
 
 
进行验证
[root@server named]# nslookup
> www.mafei.com
Server:         192.168.142.2
Address:        192.168.142.2#53
 
Name:   www.mafei.com
Address: 192.168.142.2
> www.fei.com
Server:         192.168.142.2
Address:        192.168.142.2#53
 
Name:   www.fei.com
Address: 192.168.142.2
> 192.168.142.2
Server:         192.168.142.2
Address:        192.168.142.2#53
 
2.142.168.192.in-addr.arpa      name = www.mafeifei.com.
 
好了,做到这里恭喜你DNS服务器可以对你说easy 轻松搞定