接續第一部分理論,本文實戰部署 BIND 9,涵蓋 RPM/源碼安裝、純快取服務器與主授權服務器完整配置檔案範例。
rpm -Uhv bind-9.x.x.rpm
rpm -Uhv bind-devel-9.x.x.rpm
rpm -Uhv caching-nameserver-x.x.noarch.rpm
tar zxpf bind-src.tar.gz
# 編輯 Makefile.set
DESTLIB=/usr/lib/bind/lib
DESTINC=/usr/lib/bind/include
make && make install
options {
directory "/var/named";
// query-source address * port 53; # 防火牆環境取消註釋
forwarders { 172.16.0.1; 172.16.0.11; }; # 上游 DNS
};
zone "." {
type hint;
file "named.ca";
};
zone "0.0.127.in-addr.arpa" {
type master;
file "named.local";
};
@ IN SOA localhost. root.localhost. (
2024011501 ; Serial
28800 ; Refresh (8h)
14400 ; Retry (4h)
3600000 ; Expire (1000h)
86400 ) ; Minimum (1d)
IN NS localhost.
1 IN PTR localhost.
# 從根伺服器獲取
dig @a.root-servers.net . ns > /var/named/named.ca
# 或從安裝媒體複製
以 test.com / 172.16.0.0/24 為例
zone "test.com" {
type master;
file "named.test.com";
};
zone "0.16.172.in-addr.arpa" {
type master;
file "named.172.16.0";
};
@ IN SOA ns.test.com. hostmaster.test.com. (
2024011501 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS ns.test.com.
IN NS ns2.test.com.
ns IN A 172.16.0.1
ns2 IN A 172.16.0.11
www IN A 172.16.0.2
ftp IN CNAME www.test.com.
mail IN A 172.16.0.3
@ IN MX 10 mail.test.com.
@ IN SOA ns.test.com. hostmaster.test.com. (
2024011501 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS ns.test.com.
1 IN PTR ns.test.com.
11 IN PTR ns2.test.com.
2 IN PTR www.test.com.
3 IN PTR mail.test.com.
. (如 ns.test.com.)rndc reload 或 systemctl reload named 生效named-checkconf、named-checkzone test.com /var/named/named.test.com