Unbound 是一款高效能的驗證、遞迴與快取 DNS 解析器。以下示範在 CentOS 7 上把它建成一台本機快取伺服器,並向上游公共 DNS 轉發查詢。
# hostnamectl # ip addr show | grep inet
# yum update -y # yum install unbound -y
# cp /etc/unbound/unbound.conf /etc/unbound/unbound.conf.original
# vim /etc/unbound/unbound.conf
主要需要調整的項目:
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
# systemctl start unbound.service # systemctl enable unbound.service
drill india.com @192.168.0.50
# firewall-cmd --add-service=dns # firewall-cmd --add-service=dns --permanent
# unbound-control status
# unbound-control dump_cache > /tmp/DNS_cache.txt
# unbound-control dump_cache < /tmp/DNS_cache.txt
# unbound-control lookup google.com
用 flush 可清除單筆記錄(A、AAAA、NS、SOA、CNAME、MX、PTR 等),flush_zone 則清空整個區域:
# unbound-control flush www.digitalocean.com # unbound-control flush_zone tecmintlocal.com
Unbound 服務端 IP 為 192.168.0.50,客戶端將主、次要 DNS 都指向它:
Primary DNS : 192.168.0.50 Secondary DNS : 192.168.0.50
# /etc/init.d/network restart
# elinks aol.com # dig aol.com
若 dig 的查詢時間在第二次明顯變短,就代表快取生效了。