一、dns安装

rpm -ivh 以下各包

bind-9.3.4-10.P1.el5.i386.rpm

bind-chroot-9.3.4-10.P1.el5.i386.rpm

caching-nameserver-9.3.4-10.P1.el5.i386.rpm

   、配置域和域名的名解析文件

      1.修改/var/named/chroot/etc/named.conf文件,添加区域:

     

      vi   /var/named/chroot/etc/named.conf

options

{

        directory "/var/named"; // the default

        dump-file               "data/cache_dump.db";

        statistics-file         "data/named_stats.txt";

        memstatistics-file      "data/named_mem_stats.txt";

};

zone "henancatv.com" IN {

               type master;

               file "henancatv.com.zone";

               allow-update { none; };

      };

include "/etc/rndc.key";

 

 

  2 /var/named/chroot/var/named/下添加区域文件

      cp -p localdomain.zone henancatv.com.zone

   

vi  henancatv.com.zone

$TTL    60

henancatv.com.          IN SOA  jyportal.henancatv.com. root.henancatv.com. (

                                        45              ; serial (d. adams)

                                        3H              ; refresh

                                        15M             ; retry

                                        1W              ; expiry

                                        1D )            ; minimum

                IN NS           localhost

localhost       IN A            127.0.0.1

jyportal        IN A            172.25.41.186

portal          IN A            172.30.93.202

favorite        IN A            172.30.93.19

bookmark        IN A            172.30.93.19

search          IN A            172.30.93.19

     

3修改 /etc/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 localhost_resolver {

        match-clients      { any; };//允许谁来查询解析文件

        match-destinations { any; };//解析目标

        recursion yes;

        include "/etc/named.rfc1912.zones";

};

 

  三、启动name服务,命令:

        /etc/init.d/named start 或者service named start

 四、 查看端口是否启动,看是否启动953 , 53 端口,命令:

    

     netstat -lntp  

二 、利用tar包安装dns实现本机多dns运行

安装软件:

tar xfz bind-9.3.1rc1.tar.gz 

cd bind-9.3.1rc1

编译配置
[root@linux bind-9.3.1rc1]#./configure --prefix=/usr/local/named --enable-threads #--enable-threads开启多线程处理能力
[root@linux bind-9.3.1rc1]#make
[root@linux bind-9.3.1rc1]#make install
进入/usr/local/named 建立etc目录
[root@linux bind-9.3.1rc1]#cd /usr/local/named
[root@linux named]# mkdir etc
生成rndc控制命令的key文件
[root@linux named]# sbin/rndc-confgen > etc/rndc.conf
rndc.conf文件中提取named.conf用的key
root@linux named]# cd etc
[root@linux etc]# tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf
自动在/usr/local/named/etc 生成named,conf文件

 vi  /usr/local/named/etc/named.conf
//

// named.conf for Red Hat caching-nameserver

//

options {

       listen-on port 5000 {any;};

        directory "/var/named";

        dump-file "/var/named/data/cache_dump.db";

        statistics-file "/var/named/data/named_stats.txt";

        /*

         * If there is a firewall between you and nameservers you want

         * to talk to, you might need to uncomment the query-source

         * directive below.  Previous versions of BIND always asked

         * questions using port 53, but BIND 8.1 uses an unprivileged

         * port by default.

         */

         query-source address * port 5000;

};

//

// a caching only nameserver config

//

controls {

        inet 127.0.0.1 allow { localhost; } keys { rndckey; };

};

zone "." IN {

        type hint;

        file "named.ca";

};

zone "localdomain" IN {

        type master;

        file "localdomain.zone";

        allow-update { none; };

};

zone "localhost" IN {

        type master;

        file "localhost.zone";

        allow-update { none; };

};

zone "0.0.127.in-addr.arpa" IN {

        type master;

        file "named.local";

        allow-update { none; };

};

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 "henancatv.com" IN {

        type master;

        file "henancatv.com.zone";

        allow-update { none; };

};

include "/usr/local/named/etc/rndc.key";

建立文件:named.pid

mkdir -p /usr/local/named/var/run 

  cd  /usr/local/named/var/run 

  touch  named.pid

复制多个dns配置文件组成集群

cp /usr/local/named/etc/named.conf  /usr/local/named/etc/named1.conf

cp /usr/local/named/etc/named.conf  /usr/local/named/etc/named2.conf

cp /usr/local/named/etc/named.conf  /usr/local/named/etc/named2.conf

    只需要修改里面的端口和区域文件即可

配置正向区域文件:

mkdir -p  /var/named/ 

 cat dvnbj.com.zone 

$TTL    60

@               IN SOA  ns1.dvnbj.com. root.dvnbj.com. (

                                        45              ; serial (d. adams)

                                        3H              ; refresh

                                        15M             ; retry

                                        1W              ; expiry

                                        1D )            ; minimum

                IN NS           ns1.dvnbj.com.

                IN MX 0         email.dvnbj.com.

ns1             IN A            192.168.12.130

www             IN A            192.168.12.101

 cat henancatv.com.zone 

$TTL    60

@               IN SOA  ns1.henancatv.com. root.henancatv.com. (

                                        45              ; serial (d. adams)

                                        3H              ; refresh

                                        15M             ; retry

                                        1W              ; expiry

                                        1D )            ; minimum

                IN NS           ns1.henancatv.com.

                IN MX 0         email.henancatv.com.

ns1             IN A            192.168.12.130

www             IN A            192.168.12.101

启动dns

usr/local/named/sbin/named -c /usr/local/named/etc/named.conf &

usr/local/named/sbin/named -c /usr/local/named/etc/named-lvze.conf &
netstat -lntpu

查看dns端口、为自定义的端口

 netstat -lnut


可查看cat /var/log/message文件看其是否有错误

cat /etc/resolv.conf 

nameserver 192.168.0.222

测试: ping  www.dvnbj.com

       Ping  www.henancatv.com


然后操作F5,使一些客户端的ip解析查询找50000端口,另外一些客户端走其他端口。。