智能DNS就是根据请求来源的ip来返回不同的结果,在CDN中客户的就近访问起了重要的作用。

1.编译安装bind9.6 (由于要用到bindview功能,所以要用版本9)

tar zxvf bind-9.6.0.tar.gz

./configure --prefix=/usr/local/named --enable-threads

make&&make install

 

编译选项--enable-threads据说能发挥多核cpu的优势

 

2.2、创建named.conf文件

[root@ns bind-9.6.0]# cd /usr/local/named/

[root@ns named] #sbin/rndc-confgen >./etc/rndc.conf

[root@ns named]# cd etc/

[root@ns etc]# tail -10 rndc.conf |head -9|sed s/#\//g >named.conf

[root@ns etc]# cat named.conf

简单CDN之智能DNS_第1张图片

接着在下面添加配置

配置分段的,语法类似C

logging { 

        channel default_syslog { syslog local2; severity notice; };

        channel audit_log { file "/var/log/named.log"; severity info; 

        print-time yes;print-category  yes;print-category  yes; };

        category default { default_syslog; }; 

        category general { default_syslog; }; 

        category security { audit_log; default_syslog; }; 

        category config { default_syslog; }; 

        category resolver { audit_log; }; 

        category xfer-in { audit_log; }; 

        category xfer-out { audit_log; }; 

        category notify { audit_log; }; 

        category client { audit_log; }; 

        category network { audit_log; }; 

        category update { audit_log; }; 

        category queries { audit_log; }; 

        category lame-servers { audit_log; };

        };

 

options {

        directory "/var/named/";

        pid-file "/var/named/named.pid";

        statistics-file "/var/named/named.stats"; 

        dump-file "/var/log/named.dump"; 

        zone-statistics yes;

        auth-nxdomain yes;

        notify yes;

        transfer-format many-answers;

        max-transfer-time-in 60;

        interface-interval 0;

        listen-on-v6 { any; };

        };

以上为全局配置,定义一些文件存放位置等。

接着添加用于测试

acl "TEST1"{

           192.168.1.0/24;

           192.168.1.213/32;

            };

 

acl "TEST2"{

            192.168.10.0/24;

             192.168.1.214/32;

            };

 

acl "OTHER_ALL"{
                                any;
                               }; 

 

 

view "view_test1"{

 

            match-clients{TEST1;};

             zone "fox.com"{

             type master;

             file "master/1/fox.com";

             };

                 };

 

view "view_test2"{

 

            match-clients{TEST2;};

            zone "fox.com"{

            type master;

            file "master/2/fox.com";

             };

                 };

 

 view "view_other"{
      
        match-clients{OTHER_ALL;};
        zone "fox.com"{
        type master;
        file "master/other/fox.com";
        };
          };

 

 

 

acl{}用于 指定不同客户的ip地址(段)。如果ip量大可以写在外部文件中.

view{}用于对指定acl给出相对应的.def(区域数据文件)。

acl "OTHER_ALL" 匹配剩余的,view{}的顺序很关键。

 

bind的主配置文件就这样

 

3创建目录与主区域文件

mkdir /var/named

mkdir -p /var/named/master/1

mkdir -p /var/named/master/2

mkdir -p /var/named/master/3

 

master/1/fox.com

master/2/fox.com

包含不同请求ip地址对应的区域文件

 

vim master/1/fox.com

 

$TTL 3600

$ORIGIN fox.com.

@ IN SOA ns.fox.com. root.ns.fox.com.(

2005121013 ;Serial 

3600 ; Refresh ( seconds ) 

900 ; Retry ( seconds ) 

68400 ; Expire ( seconds ) 

15 );Minimum TTL for Zone ( seconds )

  

IN   NS  ns.fox.com.

@  IN   192.168.1.201

ns   IN   A  192.168.1.201

www  IN   A  192.168.1.11

 

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

vim master/2/fox.com

 

$TTL 3600

$ORIGIN fox.com.

@ IN SOA ns.fox.com. root.ns.fox.com.(

2005121013 ;Serial

3600 ; Refresh ( seconds )

900 ; Retry ( seconds )

68400 ; Expire ( seconds )

15 );Minimum TTL for Zone ( seconds )

  

@  IN  NS   ns.fox.com.

@   IN  A  192.168.1.212

ns   IN  A  192.168.1.212

www  IN  192.168.1.22

 

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

 

vim master/other/fox.com

 

$TTL 3600

$ORIGIN fox.com.

@ IN SOA ns.fox.com. root.ns.fox.com.(

2005121013 ;Serial

3600 ; Refresh ( seconds )

900 ; Retry ( seconds )

68400 ; Expire ( seconds )

15 );Minimum TTL for Zone ( seconds )

  

@  IN  NS   ns.fox.com.

@   IN  A  192.168.3.212

ns   IN  A  192.168.3.212

www  IN  192.168.3.22

 

3.启动named

/usr/lcoal/bind/sbin/named -g &

如果配置文件没错,服务就在后台运行了,注意如果配置了view,那在view外边就不能设置zone 区域了。

根据配置,我们预料192.168.1.0/24 段的客户得到的地址将与192.168.10.0/24的不同,我们看下结果

 

简单CDN之智能DNS_第2张图片 简单CDN之智能DNS_第3张图片 简单CDN之智能DNS_第4张图片

结果是不一样的,实现了智能dns

测试的dns服务器有2块网卡,分别对应192.168.1.0/24 和 192.168.10.0/24