DNS的负载均衡和递归与迭代查询
一、DNS的负载均衡
//DNS服务器资源解析记录的类型:
// NS:DNS服务器声明记录
// A:正向解析记录
// CNAME:解析记录的别名
// PTR:反向解析记录
// 我们可以配置多个服务器来实现负载均衡
[root@tk ~]# cat /var/named/test.cn.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
test.cn. NS tk
tk A 10.0.0.200
www A 10.0.0.201
www A 10.0.0.202
[root@tk ~]# systemctl restart named
二、 DNS的泛域名解析
// DNS的泛域名解析,就是都匹配不到的时候,此时就会匹配到*的地址
[root@tk ~]# cat /var/named/test.cn.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
test.cn. NS tk
tk A 10.0.0.200
www A 10.0.0.201
www A 10.0.0.202
* A 1.1.1.1
[root@tk ~]#
// 我们进行测试
[root@gitlab ~]# nslookup abc.test.cn
Server: 10.0.0.200
Address: 10.0.0.200#53
Name: abc.test.cn
Address: 1.1.1.1
[root@gitlab ~]# nslookup www.test.cn
Server: 10.0.0.200
Address: 10.0.0.200#53
Name: www.test.cn
Address: 10.0.0.201
Name: www.test.cn
Address: 10.0.0.202
[root@gitlab ~]#
三、 DNS的解析记录的别名
// 解析别名可以让我们此时的解析结果与其他的域名一样
[root@tk ~]# cat /var/named/test.cn.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
test.cn. NS tk
tk A 10.0.0.200
www A 10.0.0.201
www A 10.0.0.202
abc A 10.0.0.203
* A 1.1.1.1
bieming CNAME abc
[root@tk ~]#
[root@gitlab ~]# nslookup abc.test.cn
Server: 10.0.0.200
Address: 10.0.0.200#53
Name: abc.test.cn
Address: 10.0.0.203
[root@gitlab ~]# nslookup bieming.test.cn
Server: 10.0.0.200
Address: 10.0.0.200#53
bieming.test.cn canonical name = abc.test.cn.
Name: abc.test.cn
Address: 10.0.0.203
[root@gitlab ~]#
四、递归查询
// 虚拟机B:构建DNS服务器负责b.test.cn
[root@gitlab ~]# yum -y install bind bind-chroot
[root@gitlab named]# cat /etc/named.conf
//
// named.conf
options {
directory "/var/named";
};
zone "b.test.cn" IN {
type master;
file "b.test.cn.zone";
};
[root@gitlab named]# cat b.test.cn.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
b.test.cn. NS gitlab
gitlab A 10.0.0.205
www A 10.10.10.10
[root@gitlab named]#
[root@gitlab named]# systemctl restart named
虚拟机A:子域授权
[root@tk ~]# cat /var/named/test.cn.zone
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
test.cn. NS tk
b.test.cn. NS gitlab
tk A 10.0.0.200
gitlab A 10.0.0.205
www A 10.0.0.201
www A 10.0.0.202
abc A 10.0.0.203
* A 1.1.1.1
bieming CNAME abc
[root@tk ~]#
[root@tk ~]# systemctl restart named
// 虚拟机B:测试
[root@gitlab named]# nslookup www.b.test.cn
Server: 10.0.0.200
Address: 10.0.0.200#53
Non-authoritative answer:
Name: www.b.test.cn
Address: 10.10.10.10
五、迭代查询
[root@tk ~]# cat /etc/named.conf
//
// named.conf
//
options {
directory "/var/named";
// 禁用递归查询
recursion no;
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
zone "test.cn" IN {
type master;
file "test.cn.zone";
};
zone "test1.cn" IN {
type master;
file "test1.cn.zone";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
[root@tk ~]#
[root@tk ~]# systemctl restart named
// 在B主机上进行测试
[root@gitlab named]# dig @10.0.0.200 www.b.test.cn
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.8 <<>> @10.0.0.200 www.b.test.cn
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33847
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 2
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.b.test.cn. IN A
;; AUTHORITY SECTION:
b.test.cn. 86400 IN NS gitlab.test.cn.
;; ADDITIONAL SECTION:
gitlab.test.cn. 86400 IN A 10.0.0.205
;; Query time: 2 msec
;; SERVER: 10.0.0.200#53(10.0.0.200)
;; WHEN: Thu Dec 23 00:24:37 CST 2021
;; MSG SIZE rcvd: 79
[root@gitlab named]#