coreDNS的基本安装在《DNS 系列-01 coredns 和 bind 的简单使用及性能对比》已经进行过阐述了。这里就不做赘述了。这里只要介绍coreDNS的插件的基本使用方法。
log
coredns的日志插件,日志级别共有四级
建议的log插件使用格式如下
1 2 3
| log [域名] [日志格式] { class type[all, success, error, denial] }
|
这里给出log的默认日志相关配置。
1 2 3 4 5 6 7 8 9 10 11 12 13
| .:53 { errors health { lameduck 5s } hosts log forward . 8.8.8.8:53 8.8.4.4:53 /etc/resolv.conf cache 30 loop reload loadbalance }
|
注意:log支持日志格式在一定规则内自定义,如果需要请查阅官方文档。日志存储位置这个有问题,还在研究。
hosts
coredns的hosts插件,能够让你和管理hosts文件一样简单又便捷的管理的域名解析记录。hosts插件可以指定解析文件。
这里给出一个简单的使用实例。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| .:53 { errors health { lameduck 5s } hosts /etc/coredns/zxzmcode.cn { ttl 60 reload 1m fallthrough } log . { class error } forward . 8.8.8.8:53 8.8.4.4:53 /etc/resolv.conf cache 30 loop reload loadbalance }
|
对应的/etc/coredns/zxzmcode.cn文件如下
1 2 3 4 5 6 7 8 9 10
| [root@coredns ~]# cat /etc/coredns/zxzmcode.cn 10.10.195.191 191.zxzmcode.cn 10.10.195.192 192.zxzmcode.cn 10.10.195.193 193.zxzmcode.cn 10.10.195.194 194.zxzmcode.cn 10.10.195.195 195.zxzmcode.cn 10.10.195.196 196.zxzmcode.cn 10.10.195.197 197.zxzmcode.cn 10.10.195.198 198.zxzmcode.cn 10.10.195.199 199.zxzmcode.cn
|
file
file插件的功能和Bind中解析记录配置的方式很相似。但是稍微简单一下。
通过阅读官方文档发现,file需要和transfer插件一起使用。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| .:53 { errors health { lameduck 5s } hosts /etc/coredns/zxzmcode.cn { ttl 60 reload 1m fallthrough } log { class all } file /etc/coredns/test.org test.org transfer { to * } forward . 8.8.8.8:53 8.8.4.4:53 /etc/resolv.conf cache 30 loop reload loadbalance }
|
对应的file文件如下
1 2 3 4 5 6 7
| $ORIGIN test.org. @ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2017042745 7200 3600 1209600 3600 3600 IN NS a.iana-servers.net. 3600 IN NS b.iana-servers.net.
www IN A 192.168.195.11 test IN A 192.168.96.246
|
etcd
coredns的相关配置
coredns推荐使用etcd作为域名存储数据库,就像bind能通过mysql存储对应的信息一样。
coredns使用etcd作为数据存储中心,简单的配置文件如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| .:53 { errors health { lameduck 5s } etcd { stubzones path /coredns endpoint http://192.168.151.101:2379 http://192.168.151.102:2379 http://192.168.151.103:2379 upstream . 114.114.114.114:53 223.5.5.5:53 /etc/resolv.conf fallthrough } log . { class error } forward . 114.114.114.114:53 223.5.5.5:53 /etc/resolv.conf cache 30 loop reload loadbalance }
|
etcd的相关配置
etcd的安装就不在这进行赘述了。这里没有使用证书验证。
这里给出对应的域名添加相关内容
A记录
这里指一个域名对应一个IP。
1
| [root@etcd-01 ~]# etcdctl put /coredns/com/linshenfanying/www/ '{"host":"192.168.96.246","ttl":10}'
|
etcd的目录结构和域名是相反的。这里添加了一个域名解析,将www.zxzmcode.cn解析到了192.168.96.246这个IP上。
这个的/coredns就是上面位置文件中的path路径,一定要匹配。要不然无法找到域名信息。
如果要删除记录 只需要将上面的put改成del就行了。
这里指一个域名对应多个IP。多个IP时,DNS默认会进行负载均衡(轮循)。
1 2 3
| [root@etcd-01 ~]# etcdctl put /coredns/com/linshenfanying/www/a '{"host":"192.168.96.246","ttl":10}' [root@etcd-01 ~]# etcdctl put /coredns/com/linshenfanying/www/b '{"host":"192.168.96.245","ttl":10}' [root@etcd-01 ~]# etcdctl put /coredns/com/linshenfanying/www/c '{"host":"192.168.96.241","ttl":10}'
|
上面的a、b、c这种值是随机定义的。
AAAA记录
将DNS解析到Ipv6地址。
1
| [root@etcd-01 ~]# etcdctl put /coredns/com/linshenfanying/www '{"host":"fe80::b86b:aaff:fe34:4080","ttl":10}'
|
CNAME记录
这里将www.zxzmcode.cn解析到www.baidu.com
1
| [root@etcd-01 ~]# etcdctl put /coredns/com/linshenfanying/www '{"host":"www.baidu.com","ttl":10}'
|
SRV记录
这个需要去研究一下。
性能测试
基础配置信息,KVM虚拟化4C4G。
单客户端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| [root@dnsperf ~]# dnsperf -d dns.txt -s 192.168.151.100 -l 120 DNS Performance Testing Tool Version 2.7.1
[Status] Command line: dnsperf -d dns.txt -s 192.168.151.100 -l 120 [Status] Sending queries (to 192.168.151.100:53) [Status] Started at: Wed Dec 22 13:40:57 2021 [Status] Stopping after 120.000000 seconds [Status] Testing complete (time limit)
Statistics:
Queries sent: 9080296 Queries completed: 9080296 (100.00%) Queries lost: 0 (0.00%)
Response codes: NOERROR 9080296 (100.00%) Average packet size: request 34, response 81 Run time (s): 120.001944 Queries per second: 75667.907513
Average Latency (s): 0.001284 (min 0.000051, max 0.023541) Latency StdDev (s): 0.000754
|
多客户端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| [root@dnsperf ~]# dnsperf -d dns.txt -s 192.168.151.100 -l120 -c1000 DNS Performance Testing Tool Version 2.7.1
[Status] Command line: dnsperf -d dns.txt -s 192.168.151.100 -l120 -c1000 [Status] Sending queries (to 192.168.151.100:53) [Status] Started at: Wed Dec 22 13:45:38 2021 [Status] Stopping after 120.000000 seconds [Status] Testing complete (time limit)
Statistics:
Queries sent: 10436459 Queries completed: 10436459 (100.00%) Queries lost: 0 (0.00%)
Response codes: NOERROR 10436459 (100.00%) Average packet size: request 34, response 81 Run time (s): 120.001238 Queries per second: 86969.594430
Average Latency (s): 0.000947 (min 0.000054, max 0.022273) Latency StdDev (s): 0.000439
|