使用Unbound配置DNS緩存服務(wù)器的實(shí)現(xiàn)步驟
簡(jiǎn)單介紹
DNS 緩存服務(wù)器 將 DNS查詢(xún)結(jié)果存儲(chǔ)在本地緩存中,并在它們的 TTL過(guò)期時(shí)從緩存中刪除資源記錄。
在本地網(wǎng)絡(luò)中設(shè)置緩存名稱(chēng)服務(wù)器,它通過(guò)在本地緩存中存儲(chǔ)最近訪(fǎng)問(wèn)的域名和 IP 地址的映射關(guān)系,減少跨Internet的DNS流量,這極大地提高了DNS名稱(chēng)解析的效率。隨著本地緩存數(shù)量增加,緩存名稱(chēng)服務(wù)器回答越來(lái)越多的客戶(hù)端查詢(xún),DNS性能將得到改善。
當(dāng)用戶(hù)在瀏覽器中輸入一個(gè)網(wǎng)址時(shí),瀏覽器會(huì)向緩存名稱(chēng)服務(wù)器發(fā)送一個(gè) DNS 查詢(xún)請(qǐng)求,如果該請(qǐng)求的域名和 IP 地址映射已經(jīng)存在于緩存中,則緩存名稱(chēng)服務(wù)器可以立即返回該映射關(guān)系,而無(wú)需再向 DNS 服務(wù)器發(fā)送請(qǐng)求,從而加快了網(wǎng)頁(yè)的加載速度。
有幾個(gè)軟件包可用于配置緩存名稱(chēng)服務(wù)器,包括bind,dnsmasq(虛擬化用的多) 和 unbound。這里使用 Unbound 安裝、配置和管理緩存名稱(chēng)服務(wù)器。
環(huán)境準(zhǔn)備
安裝 unbound
[root@servera ]# yum -y install unbound Last metadata expiration check: 0:53:24 ago on Sun 19 Feb 2023 02:19:20 PM CST. Installed: unbound-1.7.3-8.el8.x86_64
查看相關(guān)的配置文件
[root@servera ]# rpm -qlc unbound /etc/sysconfig/unbound /etc/unbound/conf.d/example.com.conf /etc/unbound/keys.d/example.com.key /etc/unbound/local.d/block-example.com.conf /etc/unbound/unbound.conf [root@servera ]#
編輯配置文件
編輯配置文件 /etc/unbound/unbound.conf
幫助文檔查看
[root@servera ]# man unbound.conf
常見(jiàn)的配置信息
定義網(wǎng)絡(luò)監(jiān)聽(tīng)
在 server 子句中,定義網(wǎng)絡(luò)監(jiān)聽(tīng),下面為不同的監(jiān)聽(tīng)配置,監(jiān)聽(tīng)I(yíng)PV4和IPv6
interface:172.25.250.10 interface:2001:db8:1001:f0 interface-automatic:no
- 默認(rèn) UNbound 監(jiān)聽(tīng) localhost 網(wǎng)絡(luò)接口。
- 如果設(shè)置監(jiān)聽(tīng) 0.0.0.0或者::0,則將會(huì)監(jiān)聽(tīng)所有接口,同時(shí)需要設(shè)置interface-automatic為yes(表示 DNS 服務(wù)器將自動(dòng)選擇最佳的網(wǎng)絡(luò)接口來(lái)監(jiān)聽(tīng) DNS 查詢(xún)請(qǐng)求)。否則設(shè)置interface-automatic為no
- 如果此時(shí)本地還運(yùn)行 libvirtd 服務(wù),并且 Unbound 綁定到所有接口,將導(dǎo)致 Unbound 無(wú)法啟動(dòng)。因?yàn)?libvirtd會(huì)運(yùn)行dnsmasq,而dnsmasq也會(huì)在本地接口上監(jiān)聽(tīng)53端口。
網(wǎng)絡(luò)監(jiān)聽(tīng)配置Demo
interface: 0.0.0.0 # interface: ::0 # interface: 192.0.2.153 # interface: 192.0.2.154 # interface: 192.0.2.154@5003 # interface: 2001:DB8::5 # # for dns over tls and raw dns over port 80 # interface: 0.0.0.0@443 # interface: ::0@443 # interface: 0.0.0.0@80 # interface: ::0@80 # enable this feature to copy the source address of queries to reply. # Socket options are not supported on all platforms. experimental. # interface-automatic: yes # # NOTE: Enable this option when specifying interface 0.0.0.0 or ::0 # NOTE: Disabled per Fedora policy not to listen to * on default install # NOTE: If deploying on non-default port, eg 80/443, this needs to be disabled interface-automatic: yes
訪(fǎng)問(wèn)控制列表
在 server 子句中,定義訪(fǎng)問(wèn)控制列表。
使用access-control選項(xiàng)指定哪些客戶(hù)端可以進(jìn)行遞歸查詢(xún)??梢灾付ňW(wǎng)絡(luò)或IP地址,控制類(lèi)型:
- allow,允許訪(fǎng)問(wèn)
- refuse,阻止訪(fǎng)問(wèn)并將DNS REFUSED錯(cuò)誤發(fā)送給客戶(hù)端
- deny,阻止訪(fǎng)問(wèn),不發(fā)送響應(yīng)
示例:
# access-control: 0.0.0.0/0 refuse # access-control: 127.0.0.0/8 allow # access-control: ::0/0 refuse # access-control: ::1 allow # access-control: ::ffff:127.0.0.1 allow access-control: 172.25.250.0/24 allow
配置訪(fǎng)問(wèn)控制, 禁止除預(yù)期客戶(hù)端之外的主機(jī)使用遞歸緩存名稱(chēng)服務(wù)器 。
如果允許Internet上的任何主機(jī)遞歸查詢(xún)您的服務(wù)器,則攻擊者可以使用它對(duì)第三方執(zhí)行DNS放大分布式拒絕服務(wù)攻擊。詳情參考https://blog.cloudflare.com/deep-inside-a-dns-amplification-ddos-attack/。
轉(zhuǎn)發(fā)請(qǐng)求到其他緩沖名稱(chēng)服務(wù)器
轉(zhuǎn)發(fā)請(qǐng)求到其他緩沖名稱(chēng)服務(wù)器:
如果此名稱(chēng)服務(wù)器無(wú)法訪(fǎng)問(wèn)Internet,但可以訪(fǎng)問(wèn)另外一個(gè)連接Internet的DNS服務(wù)器。創(chuàng)建一個(gè) forward-zone 子句以指定要轉(zhuǎn)發(fā)的域以及將查詢(xún)轉(zhuǎn)發(fā)到的DNS服務(wù)器。
將名稱(chēng)值設(shè)置為. 轉(zhuǎn)發(fā)所有查詢(xún)
forward-zone: name:"." forward-addr:172.25.250.254
對(duì)內(nèi)部域的查詢(xún)直接發(fā)送到對(duì)該域具有權(quán)威性的名稱(chēng)服務(wù)器。
- 為轉(zhuǎn)發(fā)區(qū)域指定DNS服務(wù)器:
- 使用forward-host選項(xiàng)通過(guò)主機(jī)名
使用forward-addr選項(xiàng)通過(guò)IP地址。
# forward-zone: # name: "example.com" # forward-addr: 192.0.2.68 # forward-addr: 192.0.2.73@5355 # forward to port 5355. # forward-first: no # forward-tls-upstream: no # forward-zone: # name: "example.org" # forward-host: fwd.example.com
domain-insecure 用于指定不需要驗(yàn)證 DNSSEC 的域名。在這個(gè)選項(xiàng)中 example.com 表示不需要驗(yàn)證 example.com 域名的 DNSSEC 安全性。這意味著,當(dāng) Unbound 接收到來(lái)自 example.com 的 DNS 響應(yīng)時(shí),它不會(huì)對(duì)響應(yīng)進(jìn)行 DNSSEC 驗(yàn)證。如果 example.com 的 DNS 響應(yīng)被篡改或偽造,那么 Unbound 將不會(huì)檢測(cè)到這種攻擊
domain-insecure: "example.com"
證書(shū)相關(guān)生成
unbound-control-setup 在 /etc/unbound 目錄下生成了 unbound_server.key 和 unbound_control.key 兩個(gè) RSA 私鑰文件,并生成了 unbound_server.pem 和 unbound_control.pem 兩個(gè)證書(shū)文件。
其中,unbound_server.pem 是自簽名的服務(wù)器證書(shū),unbound_control.pem 是客戶(hù)端證書(shū),由服務(wù)器證書(shū)簽名。這個(gè)命令還輸出了證書(shū)的簽名信息和主題信息。最后,命令提示您在 unbound.conf 配置文件中啟用證書(shū)以使用它們。
[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 [root@servera ]#
配置文件語(yǔ)法檢查
[root@servera ]# unbound-checkconf unbound-checkconf: no errors in /etc/unbound/unbound.conf [root@servera ]#
啟動(dòng)DNS緩存服務(wù)器
開(kāi)啟防火墻
[root@servera ]# firewall-cmd --add-service=dns --permanent success [root@servera ]# firewall-cmd --reload success
配置開(kāi)啟自啟動(dòng),并啟動(dòng)
[root@servera ]# systemctl enable unbound --now Created symlink /etc/systemd/system/multi-user.target.wants/unbound.service → /usr/lib/systemd/system/unbound.service.
測(cè)試
[root@servera ]# dig ?@servera.lab.example.com workstation.lab.example.com ; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el8 <<>> @servera.lab.example.com workstation.lab.example.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24427 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;workstation.lab.example.com. ? IN ? ? ?A ;; ANSWER SECTION: workstation.lab.example.com. 600 IN ? ? A ? ? ? 172.25.250.9 ;; Query time: 2 msec ;; SERVER: 172.25.250.10#53(172.25.250.10) ;; WHEN: Sun Feb 19 19:21:49 CST 2023 ;; MSG SIZE ?rcvd: 72 [root@servera ]#
- HEADER 部分包含了查詢(xún)的一些基本信息,如操作碼、狀態(tài)碼、ID 等;
- QUESTION 部分表示查詢(xún)的問(wèn)題部分,包含了需要查詢(xún)的主機(jī)名和記錄類(lèi)型(A 記錄);
- ANSWER 部分則是查詢(xún)結(jié)果,其中包含了查詢(xún)到的主機(jī)名和對(duì)應(yīng)的 IP 地址。
查詢(xún)的是 lab.example.com 域名的 NS 記錄,使用的 DNS 服務(wù)器是 servera.lab.example.com
[root@servera ]# dig ?@servera.lab.example.com NS lab.example.com ; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el8 <<>> @servera.lab.example.com NS lab.example.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51183 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;lab.example.com. ? ? ? ? ? ? ? IN ? ? ?NS ;; ANSWER SECTION: lab.example.com. ? ? ? ?86400 ? IN ? ? ?NS ? ? ?bastion.lab.example.com. ;; Query time: 2 msec ;; SERVER: 172.25.250.10#53(172.25.250.10) ;; WHEN: Sun Feb 19 19:29:04 CST 2023 ;; MSG SIZE ?rcvd: 66 [root@servera ]#
查詢(xún)結(jié)果顯示該域名的 NS 記錄為 bastion.lab.example.com。在查詢(xún)結(jié)果中,
- flags 字段顯示 qr rd ra,分別表示該查詢(xún)?yōu)轫憫?yīng)(response)、遞歸查詢(xún)(recursion desired)和遞歸可用(recursion available)
- Query time 字段顯示查詢(xún)耗時(shí) 2 毫秒
- SERVER 字段顯示使用的 DNS 服務(wù)器 IP 地址為 172.25.250.10
- MSG SIZE rcvd 字段顯示收到的 DNS 響應(yīng)消息大小為 66 字節(jié)。
unbound DNS 服務(wù)器的狀態(tài)輸出結(jié)果
[root@servera ]# unbound-control status version: 1.7.3 verbosity: 1 threads: 4 modules: 3 [ ipsecmod validator iterator ] uptime: 349 seconds options: reuseport control(ssl) unbound (pid 28457) is running...
- version 字段顯示當(dāng)前 unbound 版本為 1.7.3
- verbosity 字段顯示日志詳細(xì)程度為 1
- threads 字段顯示使用了 4 個(gè)線(xiàn)程
- modules 字段顯示加載了 3 個(gè)模塊,分別是 ipsecmod、validator 和 iterator
- uptime 字段顯示 unbound 運(yùn)行時(shí)間為 349 秒
- options 字段顯示使用了 reuseport 和 control(ssl) 兩個(gè)選項(xiàng)。
- unbound 進(jìn)程的 PID 為 28457,并且正在運(yùn)行。
unbound DNS 服務(wù)器的緩存輸出結(jié)果
[root@servera ]# unbound-control dump_cache START_RRSET_CACHE ;rrset 504 1 0 3 3 bastion.lab.example.com. 504 IN A 172.25.250.254 ;rrset 86304 1 0 8 3 lab.example.com. 86304 IN NS bastion.lab.example.com. END_RRSET_CACHE START_MSG_CACHE msg lab.example.com. IN NS 33152 1 504 3 1 0 1 lab.example.com. IN NS 0 bastion.lab.example.com. IN A 0 END_MSG_CACHE EOF [root@servera ]# unbound-control dump_cache > dns_dump [root@servera ]#
START_RRSET_CACHE 和 END_RRSET_CACHE 之間的部分是存儲(chǔ)在 unbound 緩存中的 RRset 記錄,包括了 bastion.lab.example.com 域名的 A 記錄和 lab.example.com 域名的 NS 記錄。每個(gè) RRset 記錄包含了多個(gè) RRSIG 記錄,用于驗(yàn)證該 RRset 記錄的真實(shí)性。
START_MSG_CACHE 和 END_MSG_CACHE 之間的部分則是存儲(chǔ)在 unbound 緩存中的 DNS 消息記錄,包括了查詢(xún) lab.example.com 域名的 NS 記錄的 DNS 消息記錄。
[root@servera ]# dig @servera.lab.example.com servera.lab.example.com [root@servera ]# dig @servera.lab.example.com serverb.lab.example.com [root@servera ]# dig @servera.lab.example.com serverc.lab.example.com [root@servera ]#
查看緩存信息
[root@servera ]# unbound-control dump_cache START_RRSET_CACHE ;rrset 502 1 0 8 3 serverb.lab.example.com. 502 IN A 172.25.250.11 ;rrset 280 1 0 3 3 bastion.lab.example.com. 280 IN A 172.25.250.254 ;rrset 490 1 0 8 3 servera.lab.example.com. 490 IN A 172.25.250.10 ;rrset 86080 1 0 8 3 lab.example.com. 86080 IN NS bastion.lab.example.com. ;rrset 511 1 0 8 3 serverc.lab.example.com. 511 IN A 172.25.250.12 END_RRSET_CACHE START_MSG_CACHE msg serverb.lab.example.com. IN A 33152 1 502 3 1 1 1 serverb.lab.example.com. IN A 0 lab.example.com. IN NS 0 bastion.lab.example.com. IN A 0 msg lab.example.com. IN NS 33152 1 280 3 1 0 1 lab.example.com. IN NS 0 bastion.lab.example.com. IN A 0 msg servera.lab.example.com. IN A 33152 1 490 3 1 1 1 servera.lab.example.com. IN A 0 lab.example.com. IN NS 0 bastion.lab.example.com. IN A 0 msg serverc.lab.example.com. IN A 33152 1 511 3 1 1 1 serverc.lab.example.com. IN A 0 lab.example.com. IN NS 0 bastion.lab.example.com. IN A 0 END_MSG_CACHE EOF
清除緩存
[root@servera ]# unbound-control flush_zone lab.example.com. ok removed 5 rrsets, 4 messages and 0 key entries [root@servera ]# unbound-control dump_cache START_RRSET_CACHE END_RRSET_CACHE START_MSG_CACHE END_MSG_CACHE EOF [root@servera ]#
緩存導(dǎo)出和導(dǎo)入
[root@servera ]# unbound-control load_cache < dns_dump ok [root@servera ]# unbound-control dump_cache START_RRSET_CACHE ;rrset 457 1 0 3 3 bastion.lab.example.com. 457 IN A 172.25.250.254 ;rrset 86257 1 0 8 3 lab.example.com. 86257 IN NS bastion.lab.example.com. END_RRSET_CACHE START_MSG_CACHE msg lab.example.com. IN NS 33152 1 457 3 1 0 1 lab.example.com. IN NS 0 bastion.lab.example.com. IN A 0 END_MSG_CACHE EOF [root@servera ]#
到此這篇關(guān)于使用Unbound配置DNS緩存服務(wù)器的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)Unbound配置DNS緩存服務(wù)器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- win2003 DNS服務(wù)器配置方法[圖文詳解]
- win2003服務(wù)器搭建DNS服務(wù)器配置圖解教程(比較詳細(xì))
- windows server 2008 r2 DNS服務(wù)器配置圖文教程
- windows2003 DNS服務(wù)器配置(圖文詳解)
- Windows Server2012 安裝配置DNS服務(wù)器方法詳解
- Ubuntu中靜態(tài)DNS配置的方法詳解
- Linux域名服務(wù)DNS配置方法
- 完美解決linux下dns配置重啟失效的問(wèn)題
- win2003 配置DNS、NAT及搭建IIS網(wǎng)站的方法
- windows server 2008安裝配置DNS服務(wù)器
相關(guān)文章
win2003服務(wù)器搭建DNS服務(wù)器配置圖解教程(比較詳細(xì))
DNS簡(jiǎn)單地說(shuō),就是Domain Name System(域名系統(tǒng))。在一個(gè)以TCP/IP協(xié)議為主的網(wǎng)絡(luò)環(huán)境中,DNS是一個(gè)非常重要而且常用的系統(tǒng)。其主要的功能就是將我們?nèi)菀子洃浀木W(wǎng)址域名(Domain Name)與不容易記憶的IP地址作自動(dòng)解析互換2012-05-05Windows?Server?2019?DNS服務(wù)器的配置與管理之DNS反向解析
這篇文章主要介紹了Windows?Server?2019?DNS服務(wù)器的配置與管理之DNS反向解析,需要的朋友可以參考下2023-05-05新網(wǎng)互聯(lián) 域名 泛解析設(shè)置方法
好多朋友需要使用泛解析,其實(shí)什么是泛解析,和泛解析有什么好處呢。大家看完這篇文章就知道了。2009-06-06DNS_PROBE_FINISHED_NXDOMAIN錯(cuò)誤如何修復(fù)
DNS_PROBE_FINISHED_NXDOMAIN是您嘗試訪(fǎng)問(wèn)網(wǎng)站時(shí)隨時(shí)可能在瀏覽器上顯示的錯(cuò)誤,本文主要介紹了3種解決方法,具有一定的參考價(jià)值,感興趣的可以了解一下2023-05-05Windows?Server?2019?DNS服務(wù)器的配置與管理之主、輔域名服務(wù)器
這篇文章主要介紹了Windows?Server?2019?DNS服務(wù)器的配置與管理之主、輔域名服務(wù)器,需要的朋友可以參考下2023-05-05