在我國目前的網絡環境下面,多個運營商並存,運營商之間的存在必定的網絡互通問題,若是把來自不一樣的運營商或者地域的全部用戶經過簡單的A記錄分配到一個機房,那麼就存在部分網民訪問延時大或者丟包的問題。那麼bind裏面就提供了視圖(Dns view ) 技術來解決這個問題,DNS視圖 就是對同一個資源記錄根據的DNS請求來源IP地址不一樣,分配到解析器的解析結果也不一樣,也就是說它能夠提供這樣的功能。服務器
咱們在這裏配置的是模擬環境,環境以下:
網絡
都是採用Centos6.6系統,yum安裝的bind服務。優化
dns服務器的named配置以下:debug
[root@localhost etc]# cat /etc/named.conf options { 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"; recursion yes; dnssec-enable yes; dnssec-validation yes; /* Path to ISC DLV key */ bindkeys-file "/etc/named.iscdlv.key"; managed-keys-directory "/var/named/dynamic"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; channel query_log { #開啓請求日誌 file "/var/log/dns/query.log" versions 5 size 30m; severity info; print-time yes; print-category yes; }; category queries { query_log; }; }; view "view_localnet_45" { match-clients { # 使用match-clients指令,指定匹配來自這些用戶的ip localnet45; # 寫的是acl配置文件定義的aclname }; zone "ljf.com" { type master; file "ljf.com.zone45"; #不一樣的匹配規則我這裏寫的是用不一樣的域名文件,方便管理 }; }; view "view_localnet_141" { match-clients { localnet141; }; zone "ljf.com" { type master; file "ljf.com.zone141"; }; }; #include "/etc/named.rfc1912.zones"; # 註釋掉這條,由於開啓view之後,全部的zone必須包含在view裏面,否則啓動報錯。 include "/etc/named.root.key"; include "/etc/named/acl/localnet141.conf"; # 引入acl配置文件 include "/etc/named/acl/LocalNet45.conf"; # 引入acl配置文件
下面咱們看看ACL的配置文件:日誌
[root@localhost named]# cat /etc/named/acl/localnet141.conf acl "localnet141" { 192.168.141.0/24; #針對192.168.141的網段 }; You have new mail in /var/spool/mail/root [root@localhost named]# cat /etc/named/acl/LocalNet45.conf acl "localnet45" { # 定義acl的名字,方便named.conf裏面的match-clients 去調用 192.168.45.0/24; # 針對192.168.45的網段 };
再看下zone的file內容 :code
[root@localhost named]# cat /var/named/ljf.com.zone141 $TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum @ IN NS ns www IN A 192.168.141.3 ns IN A 102.168.141.3 [root@localhost named]# cat /var/named/ljf.com.zone45 $TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum @ IN NS ns www IN A 192.168.45.128 test IN A 192.168.45.2 ns IN A 192.168.45.129
那麼就開始去驗證咱們剛纔的配置的DNS功能
在192.168.141.4上解析域名blog
[root@localhost ~]# dig @192.168.141.3 www.ljf.com +short 192.168.141.3
在192.168.45.128上解析域名dns
root@leo-virtual-machine:~# dig @192.168.45.129 www.ljf.com +short 192.168.45.128
由解析結果看得出來,在不一樣網段解析同一個域名,解析結果確實不一樣,展現了bind的view功能的強大之處ip
總結起來就是用acl指令去圈定一批來源IP,使用view的match-clients匹配該acl,爲其分配zone文件用於解析用於解析。
***資源
相信你們能夠看到,view裏面的核心內容就是匹配來源IP,那麼問題來了,這些ip哪裏來的?毫無疑問,確定是本身經過dns請求日誌去收集的
日誌配置我在這裏在貼下:
[root@localhost named]# cat /etc/named.conf ''''' logging { channel default_debug { file "data/named.run"; severity dynamic; }; channel query_log { #開啓請求日誌 file "/var/log/dns/query.log" versions 5 size 30m; severity info; print-time yes; print-category yes; }; category queries { query_log; }; }; '''''
日誌格式以下
[root@localhost named]# cat /var/log/dns/query.log 06-Nov-2016 11:56:43.045 queries: client 192.168.45.128#40987: view view_localnet_45: query: www.ljf.com IN A +E (192.168.45.129) 06-Nov-2016 11:56:43.518 queries: client 192.168.45.128#60098: view view_localnet_45: query: www.ljf.com IN A +E (192.168.45.129) '''''''''