[Master DNS] (192.168.1.10) ←Zone Transfer→ [Slave DNS] (192.168.1.20)
│
├─ Delegation → [Sub DNS] (192.168.2.10) (子域名授權)
│
└─ Query → [Client] (192.168.1.100) (測試客戶端)
平台:CentOS 7/8 / RHEL / Rocky / AlmaLinux,軟件:BIND 9 (named)
# 1. 檢查已安裝包
rpm -qa | grep bind
# 預期:bind-libs, bind-license, bind-utils (客戶端工具 dig/nslookup/host)
# 缺失:bind (服務端), bind-chroot (可選), bind-dyndb-ldap (可選)
# 2. 安裝服務端與緩存配置模板包
yum install -y bind bind-chroot bind-utils
# 或 dnf install -y bind bind-chroot bind-utils
# 3. 安裝 caching-nameserver 自動生成標準配置
yum install -y caching-nameserver
# 此包會在 /etc/named.conf 注入標準緩存服務器配置
# 並在 /var/named/ 生成區域文件模板 (named.ca, named.empty, named.localhost, named.loopback)
options {
listen-on port 53 { 127.0.0.1; 192.168.1.10; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { localhost; 192.168.1.0/24; 192.168.2.0/24; };
allow-recursion { localhost; 192.168.1.0/24; 192.168.2.0/24; };
allow-transfer { 192.168.1.20; }; # 僅允許 Slave 區域傳輸
dnssec-validation yes;
managed-keys-directory "/var/named/dynamic";
pid-file "/run/named/named.pid";
session-keyfile "/run/named/session.key";
};
logging {
channel default_debug {
file "data/named.run" versions 3 size 10m;
severity dynamic;
print-time yes; print-category yes; print-severity yes;
};
};
zone "." IN {
type hint;
file "named.ca"; # 根區域提示文件
};
zone "example.com" IN {
type master;
file "example.com.zone";
allow-update { none; }; # 動態更新需配合 TSIG/SIG(0)
allow-transfer { 192.168.1.20; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "192.168.1.zone";
allow-transfer { 192.168.1.20; };
};
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2024010101 ; Serial (YYYYMMDDNN)
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ) ; Minimum
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
ns1 IN A 192.168.1.10
ns2 IN A 192.168.1.20
www IN A 192.168.1.100
mail IN A 192.168.1.101
@ IN MX 10 mail.example.com.
ftp IN CNAME www
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2024010101
3600
1800
604800
86400 )
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
10 IN PTR ns1.example.com.
20 IN PTR ns2.example.com.
100 IN PTR www.example.com.
101 IN PTR mail.example.com.
zone "example.com" IN {
type slave;
file "slaves/example.com.zone"; # 寫入 slaves 子目錄,需 named 寫權限
masters { 192.168.1.10; };
};
zone "1.168.192.in-addr.arpa" IN {
type slave;
file "slaves/192.168.1.zone";
masters { 192.168.1.10; };
};
場景:將 sub.example.com 授權給獨立管理的 Sub DNS (192.168.2.10)
; 在 example.com.zone 中添加
sub IN NS ns1.sub.example.com.
ns1.sub IN A 192.168.2.10
效果:查詢 host.sub.example.com 時,主 DNS 返回 NS 授權記錄,解析器繼續查詢 Sub DNS。
# 1. 語法檢查
named-checkconf
named-checkzone example.com /var/named/example.com.zone
named-checkzone 1.168.192.in-addr.arpa /var/named/192.168.1.zone
# 2. 啟動服務
systemctl enable --now named
# 或 chroot 環境:systemctl enable --now named-chroot
# 3. 客戶端測試
dig @192.168.1.10 www.example.com A
dig @192.168.1.10 -x 192.168.1.100
nslookup www.example.com 192.168.1.10
host www.example.com 192.168.1.10
# 4. 區域傳輸驗證 (僅授權 IP)
dig @192.168.1.10 example.com AXFR
dig @192.168.1.20 example.com AXFR # Slave 上驗證
# 5. 遞歸查詢驗證
dig @192.168.1.10 www.google.com A +trace
dnssec-keygen / dnssec-signzone 簽名區域,發布 DS 記錄到父區域DNS 服務器架設核心:區域文件規範 (SOA/NS/Serial) + ACL 精準控制 + 主從同步驗證 + 子域授權委派 + 持續監控審計。