1. 程式人生 > 實用技巧 >DNS--智慧地址解析(view檢視)

DNS--智慧地址解析(view檢視)

域名:xinenhui.com

DNS伺服器:192.168.198.128

DNS1:192.168.198.129

DNS2:192.168.198.146

1簡介

 使客戶端就近訪問DNS伺服器來加速使用者的訪問速度提高客戶端體驗

 不同的客戶端使用同一個DNS伺服器解析同一個域名得到不同的IP

2修改主配置檔案設定view

[root@localhost ~]# vim /etc/named.conf
... acl
"DNS1" { 192.168.198.129; };        #acl用於標記不同的客戶端 acl "DNS2" { 192.168.198.146; }; view
"DNS1" {                   #view名稱 match-clients { DNS1; };             #在這個 view 中匹配到標記為 north 的客戶端 zone "." IN { type hint; file "named.ca"; }; zone "xinenhui.com" IN { type master; file "xinenhui.com.DNS1.zone";    #在解析 xinenhui.com 域時使用 xinenhui.com.DNS1.zone 這個檔案
}; }; view
"DNS2" { match-clients { DNS2; }; zone "." IN { type hint; file "named.ca"; }; zone "xinenhui.com" IN { type master; file "xinenhui.com.DNS2.zone"; }; }; view "DNS3" { match-clients { any; };            #在這個 view 中未匹配到任何標記的客戶端 zone "." IN { type hint; file
"named.ca"; }; zone "xinenhui.com" IN { type master; file "xinenhui.com.DNS3.zone";   #在解析 xinenhui.com 域時使用 xinenhui.com.DNS1.zone 這個檔案
};
};

//include "/etc/named.rfc1912.zones";    #加註釋
//include "/etc/named.root.key";

3配置區配置檔案

cp -p /var/named/named.empty /var/named/xinenhui.com.DNS1.zone
cp -p /var/named/named.empty /var/named/xinenhui.com.DNS2.zone
cp -p /var/named/named.empty /var/named/xinenhui.com.DNS3.zone
[root@localhost ~]# cat /var/named/xinenhui.com.DNS1.zone 
$TTL 3H
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      dns.xinenhui.com.
dns     A       6.6.6.6
www     A       1.1.1.1
[root@localhost ~]# cat /var/named/xinenhui.com.DNS2.zone 
$TTL 3H
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      dns.xinenhui.com.
dns     A       6.6.6.6
www     A       1.1.1.2
[root@localhost ~]# cat /var/named/xinenhui.com.DNS3.zone 
$TTL 3H
@       IN SOA  @ rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      dns.xinenhui.com.
dns     A       6.6.6.7
www     A       1.1.1.1

4檢查配置檔案是否正確重啟服務

named-checkconf
named-checkzone xinenhui.com /var/named/xinenhui.com.DNS1.zone
named-checkzone xinenhui.com /var/named/xinenhui.com.DNS2.zone
named-checkzone xinenhui.com /var/named/xinenhui.com.DNS3.zone
systemctl restart named

5使用兩個客戶端及本機分別測試

#設定DNS伺服器 
echo "nameserver 192.168.198.128" >> /etc/resolv.conf