RH358管理DNS和DNS服務器–使用Unbound配置快取名稱服務器
本章節介紹使用unbound軟體配置快取DNS,雖說配置DNS方面還是在windows server上部署更加方便,但難免出現日后需要使用的場景,還是需要學習,
專欄地址:https://blog.csdn.net/qq_41765918/category_11532281.html
文章目錄
- RH358管理DNS和DNS服務器--使用Unbound配置快取名稱服務器
- 1. 安裝和配置Unbound
- 安裝unbound
- 編輯unbound組態檔
- 啟用快取名稱服務器
- 2. 管理Unbound
- 轉儲和加載unbound快取
- 重繪unbound快取
- 3. 課本練習
- 1. 安裝unbound,
- 2. 按要求編輯server子句,
- 3. 生成私鑰和服務器證書,
- 4. 檢查unbound組態檔的語法,
- 5. 配置防火墻允許DNS流量,
- 6. 啟用并啟動unbound服務,
- 7. 通過執行查詢和檢查快取的內容來驗證快取名稱服務,
- 完成實驗
- 總結
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,
- 若喜歡金魚哥的文章,順手點個贊,也可點個關注,因為后續會不斷上干貨,

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/389110.html
標籤:其他
上一篇:Redis最常用的使用場景
下一篇:如何對nginx進行平滑升級
