金鱼哥RHCA回忆录:RH358管理DNS和DNS服务器--使用Unbound配置缓存名称服务器

举报
金鱼哥 发表于 2022/04/21 18:05:12 2022/04/21
【摘要】 第三章 管理DNS和DNS服务器--使用Unbound配置缓存名称服务器

RH358管理DNS和DNS服务器–使用Unbound配置缓存名称服务器

本章节介绍使用unbound软件配置缓存DNS。虽说配置DNS方面还是在windows server上部署更加方便,但难免出现日后需要使用的场景,还是需要学习。

此文章( 第三章 管理DNS和DNS服务器–使用Unbound配置缓存名称服务器 )收录在RHCA专栏:RHCA 回忆录

DNS服务器软件:bind,powerdns,dnsmasq,unbound,coredns

1. 安装和配置Unbound

缓存名称服务器将DNS查询结果存储在本地缓存中,并在它们的ttl过期时从缓存中删除资源记录。通常设置缓存名称服务器以代表本地网络上的客户端执行查询。这大大提高了DNS名称解析的效率,减少DNS流量在互联网上。随着缓存的增长,DNS性能会随着缓存名称服务器从其本地缓存响应越来越多的客户端查询而提高。有几个包可用于配置缓存名称服务器,包括bind、dnsmasq和unbound。在本节中,将学习如何安装、配置和管理Unbound,这是一个启用了DNSSEC验证的更安全的缓存名称服务器。

安装unbound

要将unbound配置为缓存名称服务器,请确保已安装unbound包:

[root@host ~]# yum install unbound

编辑unbound配置文件

以root用户编辑/etc/unbound/unbound.conf文件,如下所示:

  • 在server子句中,定义Unbound将侦听的网络接口。
interface: 192.0.2.100
interface: 2001:db8:1001::f0

默认情况下,Unbound只侦听本地主机网络接口。要允许远程客户端使用Unbound作为缓存名称服务器,请使用/etc/unbound/unbound.conf中server子句中的interface选项来指定要侦听的网络接口。您可以指定多个接口指令。

重要:

如果将interface设置为0.0.0.0或::0(侦听所有网络接口),则必须将interface-automatic设置为yes。否则,将interface-automatic设置为no。

如果libvirtd服务与Unbound运行在同一台机器上,并且试图绑定到所有接口,Unbound可能不会启动。这是因为,默认情况下,Libvirtd在连接到其虚拟网络的本地接口的53端口(UDP和TCP的DNS服务器端口)上运行dnsmasq

  • 允许或阻止客户端访问。

默认情况下,unbound拒绝来自除localhost以外的所有客户机的递归查询。在/etc/unbound/unbound .conf的server子句中,使用access-control选项来指定哪些客户端可以进行递归查询。可以指定网络地址或IP地址,匹配最多的将获胜。最有用的三种设置是allow,,允许访问,refuse,阻止访问并向客户端发送DNS拒绝错误,deny,阻止访问并根本不发送响应,

access-control: 172.25.0.0/24 allow
access-control: 2001:db8:1001::/32 allow
access-control: 10.0.0.0/8 refuse

重要:

配置一个access-control来禁止除您的目标客户端以外的主机使用缓存名称服务器的递归。如果你允许互联网上的任何主机使用你的服务器进行递归查询,它可以被攻击者用来对第三方执行DNS放大分布式拒绝服务攻击(DDOS)。

  • 将查询转发到另一个缓存名称服务器(可选)。

如果此名称服务器不能访问internet,但可以访问能够访问internet的名称服务器,则可能需要这样做。也可以这样做,将内部域的查询直接发送到该域的权威名称服务器。

在/etc/unbound/unbound.conf中,创建forward-zone子句来指定要转发的域和要转发查询的DNS服务器。设置name值为“.”转发所有查询。使用forward-host选项通过主机名指定转发区域的DNS服务器,或使用forward-addr选项通过IP地址指定转发区域的DNS服务器。

forward-zone:
  name: "."
  forward-addr: 172.25.254.254
  • 禁用特定未签名区域的 DNSSEC 验证(可选)。

默认情况下,unbound对接收到的所有DNS响应进行DNSSEC验证。通常希望它这样做,但有时会有一个未正确签名的内部域,因此无法通过DNSSEC验证。

/etc/unbound/unbound.conf的server子句中的domain-insecure选项指定了需要跳过DNSSEC验证的域。

domain-insecure: example.com

警告:不要仅仅为了解决DNS解析中未解释的问题而禁用DNSSEC验证。DNSSEC失败可能表明正在接收被正确拒绝的欺骗响应。

  • 保存配置文件/etc/unbound/unbound.conf。

生成私钥和服务器证书。

[root@host ~]# unbound-control-setup
setup in directory /etc/unbound
generating unbound_server.key
Generating RSA private key, 3072 bit long modulus (2 primes)
..........................................................++++
.....++++
e is 65537 (0x010001)
generating unbound_control.key
Generating RSA private key, 3072 bit long modulus (2 primes)
....................................++++
......................................++++
e is 65537 (0x010001)
create unbound_server.pem (self signed certificate)
create unbound_control.pem (signed client certificate)
Signature ok
subject=CN = unbound-control
Getting CA Private Key
Setup success. Certificates created. Enable in unbound.conf file to use

# 检查/etc/unbound/unbound.conf配置文件的语法错误。
[root@host ~]# unbound-checkconf
unbound-checkconf: no errors in /etc/unbound/unbound.conf

启用缓存名称服务器

配置防火墙允许DNS流量。如果使用firewalld,可以配置它以允许dns服务。

[root@host ~]# firewall-cmd --permanent --add-service=dns
success
[root@host ~]# firewall-cmd --reload
success

# 启动并开机启用Unbound。
[root@host ~]# systemctl enable --now unbound

2. 管理Unbound

安装了Unbound DNS服务器后,管理员有时需要操作它的缓存。unbound-control实用程序管理unbound服务器的缓存。

转储和加载unbound缓存

缓存名称服务器的管理员在解决DNS问题时可能需要转储缓存数据,比如那些由过时的资源记录引起的问题。转储Unbound DNS服务器的缓存,请使用unbound-control实用程序配合dump_cache子命令。

[root@host ~]# unbound-control dump_cache
START_RRSET_CACHE
;rrset 86395 1 0 3 3
classroom.example.com. 86395 IN A 172.25.254.254
;rrset 86395 1 0 7 3
example.com. 86395 IN NS classroom.example.com.
;rrset 86395 1 0 8 3
example.com. 86395 IN A 172.25.254.254
END_RRSET_CACHE
START_MSG_CACHE
msg example.com. IN A 33152 1 86395 3 1 1 1
example.com. IN A 0
example.com. IN NS 0
classroom.example.com. IN A 0
END_MSG_CACHE
EOF

使用dump_cache执行unbinding -control命令将缓存以文本格式转储到stdout。这个输出可以被定向到一个文件中进行存储,如果需要的话,可以使用unbound-control load_cache加载回缓存中。unbound-control load_cache命令从stdin读取数据来填充缓存。

[root@host ~]# unbound-control load_cache < dump.out
ok

刷新unbound缓存

缓存名称服务器的管理员可能还需要定期从缓存中清除过时的资源记录。缓存中的错误和过时的资源记录会阻止已改正的对应记录对客户端可用,直到资源记录上的TTL过期。与等待TTL过期不同,您可以通过对记录执行unbound-control flush来清除缓存中的过时记录:

[root@host ~]# unbound-control flush www.example.com
ok

# 使用flush_zone子命令执行unbound-control以清除Unbound DNS服务器上属于某个域的所有资源记录。
[root@host ~]# unbound-control flush_zone example.com
ok removed 3 rrsets, 1 messages and 0 key entries

3. 课本练习

[student@workstation ~]$ lab dns-unbound start

1. 安装unbound。

[root@servera ~]# yum install unbound

2. 按要求编辑server子句。

172.25.250.10接口上监听。
允许来自172.25.250.0/24子网进行查询。
免example.com区域的DNSSEC验证。
将所有查询转发到172.25.250.254
[root@servera ~]# vim /etc/unbound/unbound.conf
interface: 172.25.250.10
access-control: 172.25.250.0/24 allow
domain-insecure: "example.com"
forward-zone:
       name: .      
       forward-addr: 172.25.250.254

3. 生成私钥和服务器证书。

[root@servera ~]# unbound-control-setup
setup in directory /etc/unbound
generating unbound_server.key
Generating RSA private key, 3072 bit long modulus (2 primes)
...........++++
.......++++
e is 65537 (0x010001)
generating unbound_control.key
Generating RSA private key, 3072 bit long modulus (2 primes)
...........................................................................................................................++++
..............++++
e is 65537 (0x010001)
create unbound_server.pem (self signed certificate)
create unbound_control.pem (signed client certificate)
Signature ok
subject=CN = unbound-control
Getting CA Private Key
Setup success. Certificates created. Enable in unbound.conf file to use

4. 检查unbound配置文件的语法。

[root@servera ~]# unbound-checkconf
unbound-checkconf: no errors in /etc/unbound/unbound.conf

5. 配置防火墙允许DNS流量。

[root@servera ~]# firewall-cmd --permanent --add-service=dns
success
[root@servera ~]# firewall-cmd --reload
success

6. 启用并启动unbound服务。

[root@servera ~]# systemctl enable --now unbound
Created symlink /etc/systemd/system/multi-user.target.wants/unbound.service → /usr/lib/systemd/system/unbound.service.

7. 通过执行查询和检查缓存的内容来验证缓存名称服务。

[root@servera ~]# unbound-control dump_cache
START_RRSET_CACHE
END_RRSET_CACHE
START_MSG_CACHE
END_MSG_CACHE
EOF

[student@workstation ~]$ dig @servera.lab.example.com A workstation.lab.example.com
...........
workstation.lab.example.com. 600 IN A 172.25.250.9

[student@workstation ~]$ dig @servera.lab.example.com A servera.lab.example.com
............
servera.lab.example.com. 600 IN A 172.25.250.10

# 在服务器上,再次转储缓存。您应该在缓存中看到查询的记录。
[root@servera ~]# unbound-control dump_cache
............
msg workstation.lab.example.com. IN A 33152 1 587 3 1 1 1
workstation.lab.example.com. IN A 0
lab.example.com. IN NS 0
bastion.lab.example.com. IN A 0
msg net. IN DNSKEY 33152 1 78675 0 1 0 0
net. IN DNSKEY 0
END_MSG_CACHE
EOF

[root@servera ~]# unbound-control flush workstation.lab.example.com
ok

[root@servera ~]# unbound-control dump_cache | grep workstation

完成实验

[student@workstation ~]$ lab dns-unbound finish

总结

  • 介绍如何安装和配置Unbound。
  • 管理Unbound。

RHCA认证需要经历5门的学习与考试,还是需要花不少时间去学习与备考的,好好加油,可以噶🤪。

以上就是【金鱼哥】对 第三章 管理DNS和DNS服务器–使用Unbound配置缓存名称服务器 的简述和讲解。希望能对看到此文章的小伙伴有所帮助。

如果这篇【文章】有帮助到你,希望可以给【金鱼哥】点个赞👍,创作不易,相比官方的陈述,我更喜欢用【通俗易懂】的文笔去讲解每一个知识点,如果有对【运维技术】感兴趣,也欢迎关注❤️❤️❤️ 【金鱼哥】❤️❤️❤️,我将会给你带来巨大的【收获与惊喜】💕💕!

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。