一、添加一條A記錄(記得更改serial):算法
vim /var/named/chroot/etc/lnh.com.zone
重啓一下:vim
rndc reload
查看從服務器:後端
測試結果:服務器
master結果:負載均衡
第一種方法:是用resolv.conf中定義的DNS服務器查出百度主機的IP。dom
第二種方法(上述方法):是用本地的DNS(127.0.0.1)來查cc.lnh.com主機的IP。測試
slave結果(在master上看的):spa
二、CNAME記錄(如上)code
cname CNAME a.lnh.com.
三、MX記錄(如上)server
mx MX 5 192.168.123.123 mx MX 10 191.1.1.1
四、PTR記錄(反向解析)
MASTER:
[root@localhost etc]# cat view.conf view "View" { zone "lnh.com" { type master; file "lnh.com.zone"; allow-transfer { 192.168.222.146; }; notify yes; also-notify { 192.168.222.146; }; }; zone "168.192.in-addr.arpa" { type master; file "168.192.zone"; allow-transfer { 192.168.222.146; }; notify yes; also-notify { 192.168.222.146; }; }; };
」168.192.in-addr.arpa「固定格式,ip反過來了。
[root@localhost etc]# cat 168.192.zone $TTL 3600 ; 1 hour @ IN SOA op.lnh.com. dns.lnh.com. ( 2030 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. 102.122 IN PTR a.lnh.com. 1.1 IN PTR B.lnh.com.
此時要看看權限:chown named.named 168.192.zone
Slave配置:
[root@localhost etc]# cat view.conf view "SlaveView" { zone "lnh.com" { type slave; masters {192.168.222.145; }; file "slave.lnh.com.zone"; }; zone "168.192.in-addr.arpa" { type slave; masters {192.168.222.145; }; file "slave.168.192.zone"; }; };
這個是同步過來的:
[root@localhost etc]# cat slave.168.192.zone $ORIGIN . $TTL 3600 ; 1 hour 168.192.in-addr.arpa IN SOA op.lnh.com. dns.lnh.com. ( 2030 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN 168.192.in-addr.arpa. 1.1 PTR B.lnh.com. 102.122 PTR a.lnh.com.
注意:a.lnh.com. 後面必定要有.
查看:
[root@localhost etc]# host 192.168.122.102 127.0.0.1 Using domain server: Name: 127.0.0.1 Address: 127.0.0.1#53 Aliases: 102.122.168.192.in-addr.arpa domain name pointer a.lnh.com.
五、經過DNS實現負載均衡,,就是多加一條A記錄,,這個有個問題,當這個後端服務器掛了,他也會解析,因此不建議用,,輪詢的調度算法,沒有健康監測。
[root@localhost etc]# host cc.lnh.com 127.0.0.1 Using domain server: Name: 127.0.0.1 Address: 127.0.0.1#53 Aliases: cc.lnh.com has address 123.123.123.124 cc.lnh.com has address 123.123.123.123
六、配置DNS視圖(智能DNS),當DNS服務器接到請求時會匹配這兩個組的ip,下面的加在include上,,此時就能夠根據group來區分不用運營商分到不一樣的ip。
/var/named/chroot/etc [root@localhost etc]# vim named.conf acl group1 { 192.168.222.145; }; acl group2 { 192.168.222.146; };
[root@localhost etc]# >view.conf [root@localhost etc]# vim view.conf [root@localhost etc]# pwd /var/named/chroot/etc [root@localhost etc]# cat view.conf view "GROUP1" { match-clients { group1; }; zone "viewlnh.com" { type master; file "group1.viewlnh.com.zone"; }; }; view "GROUP2" { match-clients { group2; }; zone "viewlnh.com" { type master; file "group2.viewlnh.com.zone"; }; };
[root@localhost etc]# pwd /var/named/chroot/etc [root@localhost etc]# vim group1.viewlnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour viewlnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2030 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN viewlnh.com. op A 192.168.122.1 view A 192.168.122.1
[root@localhost etc]# pwd /var/named/chroot/etc [root@localhost etc]# vim group2.viewlnh.com.zone $ORIGIN . $TTL 3600 ; 1 hour viewlnh.com IN SOA op.lnh.com. dns.lnh.com. ( 2030 ; serial 900 ; refresh (15 minutes) 600 ; retry (10 minutes) 86400 ; expire (1 day) 3600 ; minimum (1 hour) ) NS op.lnh.com. $ORIGIN viewlnh.com. op A 192.168.122.2 view A 192.168.122.2
修改權限
[root@localhost etc]# chown named.named group*
查看,在192.168.222.145上看
[root@localhost etc]# dig @192.168.222.145 view.viewlnh.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.5 <<>> @192.168.222.145 view.viewlnh.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49593 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0 ;; QUESTION SECTION: ;view.viewlnh.com. IN A ;; ANSWER SECTION: view.viewlnh.com. 3600 IN A 192.168.122.1 ;; AUTHORITY SECTION: viewlnh.com. 3600 IN NS op.lnh.com. ;; Query time: 1 msec ;; SERVER: 192.168.222.145#53(192.168.222.145) ;; WHEN: Wed Mar 21 18:33:51 2018 ;; MSG SIZE rcvd: 71
在192.168.222.146上看
[root@localhost etc]# dig @192.168.222.145 view.viewlnh.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.5 <<>> @192.168.222.145 view.viewlnh.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11962 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0 ;; QUESTION SECTION: ;view.viewlnh.com. IN A ;; ANSWER SECTION: view.viewlnh.com. 3600 IN A 192.168.122.2 ;; AUTHORITY SECTION: viewlnh.com. 3600 IN NS op.lnh.com. ;; Query time: 3 msec ;; SERVER: 192.168.222.145#53(192.168.222.145) ;; WHEN: Wed Mar 21 18:36:16 2018 ;; MSG SIZE rcvd: 71