1 view功能原理:

   DNS服务器有一个高级的功能,能够实现不同的用户访问同一个域名,把域名解析成不同的IP地址,使用户能够访问离他最近的服务器上的数据,这就是DNS服务器的视图功能。

2view的配置:

   配置view 在主配置文件中

options {
          directory "/var/named";     
 };
view left {
 match-clients {172.16.10.0/16; };             
zone "." IN {
           type hint;
           file "named.ca";
};
zone "localhost" IN {
            type master;
            file "localhost.zone";
};
zone  "limeizhi.com" IN {
             type master;
             file "limeizhi.com.left";
};
};
    view right {
                match-clients { 192.168.2.0/24; };
            zone "limeizhi.com" IN {
                type master;
                file "limeizhi.com.right";
};
};
view default {
               match-clients { any; };
               zone "limeizhi.com" IN {
              type master;
              file "limeizhi.com.right";              
};
};

     配置left区域文件

/var/named$cat limeizhi.com.left
$TTL 600;
$ORIGIN limeizhi.com.
@   IN  SOA  @  nsadmin. (
        2014031301
        3H
        15M
        1W
        1D)
@   IN  NS  ns1.limeizhi.com.
ns1 IN  A   172.16.10.2
www IN  A   172.16.10.10

      配置right区域文件

/var/named$cat limeizhi.com.right
$TTL 600;
$ORIGIN limeizhi.com.
@   IN  SOA  @  nsadmin. (
        2014031301
        3H
        15M
        1W
        1D)
@   IN  NS  ns1.limeizhi.com.
ns1 IN  A   192.168.2.3
ns2 IN  A   192.168.2.7
www IN  A   192.168.2.12


配置要点:


(1)、如果使用了视图的功能,那么配置文件中的所有zone区域都要必须写在视图里面,如,配置文件里默认要配置的三个区域,根、127.0.0.1、1.0.0.127.in-addr.arpa都要写入视图。

(2)、在acl中定义IP地址,IP地址的写法可以是单个IP地址也可以是一个IP地址段加掩码,如:192.168.0.0/24。

(3)、视图是根据配置文件从上往下匹配的,所以希望优先访问的资源记录文件,区域应该尽量写前面。

(4)、如果定义的若干个视图的IP地址不全的话,那么可以在最后定义一个默认视图,match-clients选项中的IP地址写上any,代表如果此次访问的IP地址上面没有一个能匹配到,则在此处归类。



3检查配置是否生效

             dig -t A www.limeizhi.com @192.168.2.3

             dig -t A www.limeizhi.com @172.16.10.2

~$dig -t a www.limeizhi.com @172.16.10.2
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t a www.limeizhi.com @172.16.10.2
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41094
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;www.limeizhi.com.      IN  A
;; ANSWER SECTION:
www.limeizhi.com.   600 IN  A   172.16.10.10
;; AUTHORITY SECTION:
limeizhi.com.       600 IN  NS  ns1.limeizhi.com.
;; ADDITIONAL SECTION:
ns1.limeizhi.com.   600 IN  A   172.16.10.2
;; Query time: 4 msec
;; SERVER: 172.16.10.2#53(172.16.10.2)
;; WHEN: Wed Mar 19 09:08:51 2014
;; MSG SIZE  rcvd: 84
~$dig -t a www.limeizhi.com @192.168.2.3
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t a www.limeizhi.com @192.168.2.3
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49313
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;www.limeizhi.com.      IN  A
;; ANSWER SECTION:
www.limeizhi.com.   600 IN  A   192.168.2.12
;; AUTHORITY SECTION:
limeizhi.com.       600 IN  NS  ns1.limeizhi.com.
;; ADDITIONAL SECTION:
ns1.limeizhi.com.   600 IN  A   192.168.2.3
;; Query time: 1 msec
;; SERVER: 192.168.2.3#53(192.168.2.3)
;; WHEN: Wed Mar 19 09:19:47 2014
;; MSG SIZE  rcvd: 84

自己肉眼扫描关键点在那吧!