操作系统版本centos 5.5需要安装一些软件,使用以下命令既可

#yum -y install bind*

#yum -y install caching-nameserver

这个是做备份文件,(连权限一起复制-p)

#cd   /var/named/chroot/etc

#cp -p named.caching-nameserver.conf  named.conf

下面开始进行配置,把所有代表本地的:127.0.0.1,localhost,都改成any,表示监听所有主机的请求

#vi named.caching-nameserver.conf

示例:

-----------------------------------------------------------------------------------------------------------------------------------------------
//
// named.caching-nameserver.conf
//
// Provided by Red Hat caching-nameserver package to configure the
// ISC BIND named(8) DNS server as a caching only nameserver
// (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// DO NOT EDIT THIS FILE - use system-config-bind or an editor
// to create named.conf - edits to this file will be lost on
// caching-nameserver package upgrade.
//
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";

        // Those options should be used carefully because they disable port
        // randomization
        // query-source    port 53;
        // query-source-v6 port 53;

        allow-query     { any; };
        allow-query-cache { any; };
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
view localhost_resolver {
        match-clients      { any; };
        match-destinations { any; };
        recursion yes;
        include "/etc/named.rfc1912.zones";
};

//
// named.caching-nameserver.conf
//
// Provided by Red Hat caching-nameserver package to configure the
// ISC BIND named(8) DNS server as a caching only nameserver
// (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// DO NOT EDIT THIS FILE - use system-config-bind or an editor
// to create named.conf - edits to this file will be lost on
// caching-nameserver package upgrade.
//
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";

        // Those options should be used carefully because they disable port
        // randomization
        // query-source    port 53;
        // query-source-v6 port 53;

        allow-query     { any; };
        allow-query-cache { any; };
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
view localhost_resolver {
        match-clients      { any; };
        match-destinations { any; };
        recursion yes;
        include "/etc/named.rfc1912.zones";
};

-----------------------------------------------------------------------------------------------------------------------------------------------------

启动服务

#/etc/init.d/named start

设置服务自动启动

#chkconfig --level 35 named on

如果要开启防火墙,请输入以下指令

#iptables -A INPUT -p udp --dport 53 -j ACCEPT

#iptables -A INPUT -p tcp --dport 53 -j ACCEPT

这样就可以用该主机做DNS服务器了。

       match-clients      { any; };
        match-destinations { any; };

说是这两个可以不改,不过我没试,以后再试吧

 ----------------------------------------------------------------------------------------------------------------------------------------------------

要设置本地的DNS解析

cd /var/named/chroot/etc

vi named.caching-nameserver.conf

在最后加上

 zone "test.com" IN {         //这里就是你要的服务器名的域名,主机名在后面的一个文件里设置
        type master;
        file "test.com.zone";
        allow-update { none; };
};

// 反向解释,这个我没做,非必需,以后试
zone "1.168.192.in-addr.arpa" IN {
    type master;
    file "1.168.192.in-addr.arpa.zone";
};

 

还有要做的是

/*view localhost_resolver {
        match-clients      { localhost; };
        match-destinations { localhost; };
        recursion yes;
        include "/etc/named.rfc1912.zones";
};*/
此处要将view字段注释掉,否则在文件末尾添加zone字段后,启动named服务时,会报如下错误:“/etc/named.conf:47: when using 'view' statements, all zones must be in views”,但view还是很有用的,网上查资料所得,它可以是的bind将一个域名对应几个不同的IP地址。

# cd /var/named/chroot/var/named/
# cp –p localdomain.zone xxt401.com.zone(cp -p localhost.zone it.com.zone)
# cp –p named.local 1.168.192.in-addr.arpa.zone
# vi xxt401.com.zone(vi it.com.zone)

最后一行增加

bbs     IN      A       10.8.12.112

然后重起一下named ,然后bbs.it.com就可以被解析了