本文記錄在 Red Hat 9.0 企業內部環境(三網段:192.168.2.0/24、192.168.6.0/24、192.168.10.0/24)架設 BIND 9 DNS 伺服器的完整過程,包含套件安裝、區域檔案編寫、常見錯誤排解經驗。
若系統預設 BIND 設定反覆失敗(出現 Can't find...),建議完整移除重裝:
bind-9.2.1-16、bind-devel、bind-utils、caching-nameserver。rpm -e bind 若有相依性錯誤,依序移除相依套件(bind-devel、caching-nameserver)。rpm -ivh *.rpm。options {
directory "/var/named";
};
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
zone "." IN { type hint; file "named.ca"; }; // 根域名伺服器快取
zone "localhost" IN { type master; file "localhost.zone"; allow-update { none; }; };
zone "0.0.127.in-addr.arpa" IN { type master; file "named.local"; allow-update { none; }; };
// 三個網段的反向解析區域
zone "2.168.192.in-addr.arpa" IN { type master; file "2.168.192.file"; };
zone "6.168.192.in-addr.arpa" IN { type master; file "6.168.192.file"; };
zone "10.168.192.in-addr.arpa" IN { type master; file "10.168.192.file"; };
// 正向解析區域
zone "mytest.com" IN { type master; file "mytest.com"; };
include "/etc/rndc.key";
$TTL 86400
@ IN SOA mytest.com. root.mytest.com. (
2 ; Serial 版本號
28800 ; Refresh 3 小時
14400 ; Retry 4 小時
3600000 ; Expire 1000 小時
86400 ) ; Minimum 1 天
@ IN NS mytest.com.
7 IN PTR www.mytest.com. ; 192.168.10.7 對應 www.mytest.com
三個網段反向區域檔內容相同,僅檔名與對應 IP 末碼不同。
$TTL 86400
@ IN SOA mytest.com. root.mytest.com. (
2 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
@ IN NS ns.mytest.com.
ns IN A 192.168.10.7
www IN A 192.168.10.7
mail IN A 192.168.10.7
; 依需求新增其他主機記錄
order hosts,bind multi on
/var/named/ 目錄與檔案擁有者為 named:named,權限 640。dig @localhost www.mytest.com、nslookup、rndc status。重新安裝 BIND 套件往往能解決不明原因的解析失敗,建議遇到詭異問題時嘗試完整重裝。