Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Unbound 是一款高效能的驗證、遞迴與快取 DNS 解析器。以下示範在 CentOS 7 上把它建成一台本機快取伺服器,並向上游公共 DNS 轉發查詢。

Step 1|確認主機名與 IP

# hostnamectl
# ip addr show | grep inet
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 2|安裝 Unbound

# yum update -y
# yum install unbound -y
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 3|備份原設定

# cp /etc/unbound/unbound.conf /etc/unbound/unbound.conf.original

Step 4|編輯 unbound.conf

# vim /etc/unbound/unbound.conf
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

主要需要調整的項目:

interface: 192.168.0.50     # 監聽位址
do-ip4: yes
do-udp: yes
do-tcp: yes
logfile: /var/log/unbound
hide-identity: yes
hide-version: yes

access-control: 192.168.0.0/24 allow   # 允許的來源網段

domain-insecure: "tecmintlocal.com"

forward-zone:
    name: "."
    forward-addr: 8.8.8.8
    forward-addr: 8.8.4.4

存檔後先做語法檢查:

# unbound-checkconf /etc/unbound/unbound.conf
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 5|啟動並設為開機自啟

# systemctl start unbound.service
# systemctl enable unbound.service
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 6|用 drill 測試本機快取

drill india.com @192.168.0.50
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 7|防火牆放行 DNS

# firewall-cmd --add-service=dns
# firewall-cmd --add-service=dns --permanent
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 8|查看服務狀態

# unbound-control status
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 9|把快取匯出成文字檔

# unbound-control dump_cache > /tmp/DNS_cache.txt
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 10|從檔案還原快取

# unbound-control dump_cache < /tmp/DNS_cache.txt
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 11|查詢指定網域的解析資訊

# unbound-control lookup google.com
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 12|查看看板與清理快取

用 flush 可清除單筆記錄(A、AAAA、NS、SOA、CNAME、MX、PTR 等),flush_zone 則清空整個區域:

# unbound-control flush www.digitalocean.com
# unbound-control flush_zone tecmintlocal.com

Step 13|確認目前的轉發設定

CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 14|以 CentOS 6 作為客戶端測試

Unbound 服務端 IP 為 192.168.0.50,客戶端將主、次要 DNS 都指向它:

Primary DNS   : 192.168.0.50
Secondary DNS : 192.168.0.50
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器 CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器 CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 15|重啟網路使設定生效

# /etc/init.d/network restart
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

Step 16|最終驗證

# elinks aol.com
# dig aol.com
CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器 CentOS 7 網路服務實作(二):用 Unbound 建置 DNS 高速快取伺服器

若 dig 的查詢時間在第二次明顯變短,就代表快取生效了。

Copyright © Linux教程網 All Rights Reserved