配置之前先了解一下 bind DNS 站羣服務器站羣軟件:BIND 是一種開源的 DNS(Domain Name System)協議的實現,包含對域名的查詢和響應所需的所有站羣軟件。它是網際互聯網上最廣泛使用的一種 DNS 站羣服務器,對於類 UNIX 系統來説,已經成為事實上的標準。
為了構架 DNS 站羣服務器來解析域名或 ip 地址,我們得安裝 BIND 和 caching-nameserver 。為了 TCP 和 UDP53 資料包能通過,我們也有必要配置路由器。
安裝 BIND 站羣軟件包
1 、安裝
# yum -y install bind caching-nameserver
2 、配置
下面的例子是以公網 IP(172.16.0.80/29),區域網 IP(192.168.0.0/24),域名(linuxde.net)作説明。在配置你自己的站羣服務器時,請使用你自己的 IP 和域名。
# vim /etc/named.conf
options {
directory “/var/named”;
# query range
allow-query { localhost; 192.168.0.0/24; };
# transfer range
allow-transfer { localhost; 192.168.0.0/24; };
# recursion range
allow-recursion { localhost; 192.168.0.0/24; };
};
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
# here is the section for internal informations
vimew “internal” {
match-clients {
localhost;
192.168.0.0/24;
};
zone “.” IN {
type hint;
file “named.ca”;
};
# set zones for internal
zone “linuxde.net” IN {
type master;
file “linuxde.net.lan”;
allow-update { none; };
};
# set zones for internal
zone “0.168.192.in-addr.arpa” IN {
type master;
file “0.168.192.db”;
allow-update { none; };
};

zone “localdomain” IN {
type master;
file “localdomain.zone”;
allow-update { none; };
};

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 “255.in-addr.arpa” IN {
type master;
file “named.broadcast”;
allow-update { none; };
};

zone “0.in-addr.arpa” IN {
type master;
file “named.zero”;
allow-update { none; };
};
};

vimew “external” {
match-clients {
any;
};

zone “.” IN {
type hint;
file “named.ca”;
};

# set zones for external
zone “linuxde.net” IN {
type master;
file “linuxde.net.wan”;
allow-update { none; };
};

# set zones for external *note
zone “80.0.16.172.in-addr.arpa” IN {
type master;
file “80.0.16.172.db”;
allow-update { none; };
};
};

include “/etc/rndc.key”;

# *note : For How to write for reverse resolvimng, Write network address reversely like below.

the case for 192.168.0.0/24
network address? 192.168.0.0
range of network? 192.168.0.0 – 192.168.0.255
how to write? 0.168.192.in-addr.arpa

case of 172.16.0.80/29
network address? 172.16.0.80
range of network? 172.16.0.80 – 172.16.0.87
how to write? 80.0.16.172.in-addr.arp
設定 Zones
建立 zone 檔案以便站羣服務器能解析域名 IP 。
1 、內部 zone 檔案
這個例子使用的是內網地址(192.168.0.0/24),域名 (linuxde.net),請根據自己的具體情況配置。
# vim /var/named/linuxde.net.lan
$TTL 86400
@ IN SOA ns.linuxde.net. root.linuxde.net. (
2007041501 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL

)
# define name server
IN NS ns.linuxde.net.
# internal IP address of name server
IN A 192.168.0.17
# define mail exchanger
IN MX 10 ns.linuxde.net.

# define IP address and hostname
ns IN A 192.168.0.17
2 、外部 zone 檔案
這個例子使用的是外網地址(172.16.0.80/29),域名(linuxde.net),請替換成自己的。
# vim /var/named/linuxde.net.wan
$TTL 86400
@ IN SOA ns.linuxde.net. root.linuxde.net. (
2007041501 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
# define name server
IN NS ns.linuxde.net.
# external IP address of name server
IN A 172.16.0.82
# define Mail exchanger
IN MX 10 ns.linuxde.net.

# define IP address and hostname
ns IN A 172.16.0.82
建立 zone 檔案使站羣服務器能夠反向解析 IP 到域名。
3 、內部 zone 檔案
這個例子使用的是內網地址(192.168.0.0/24),域名(linuxde.net),請使用自己的設定替換。
# vim /var/named/0.168.192.db
$TTL 86400
@ IN SOA ns.linuxde.net. root.linuxde.net. (
2007041501 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
# define name server
IN NS ns.linuxde.net.

# define range that this domain name in
IN PTR linuxde.net.
# define IP address and hostname
IN A 255.255.255.0

17 IN PTR ns.linuxde.net.
4 、外部 zone 檔案
這例子使用外網地址(172.16.0.80/29),域名(linuxde.net),請替換成自己的。
# vim /var/named/80.0.16.172.db
$TTL 86400
@ IN SOA ns.linuxde.net. root.linuxde.net. (
2007041501 ;Serial
3600 ;Refresh
1800 ;Retry
604800 ;Expire
86400 ;Minimum TTL
)
# define name server
IN NS ns.linuxde.net.

# define range that this domain name in
IN PTR linuxde.net.
# define IP address and hostname
IN A 255.255.255.248

82 IN PTR ns.linuxde.net.
啓動 BIND
1 、完成 BIND 的配置後,在啓動 named 之前,還需要建立 chroot 環境。
# yum -y install bind-chroot
# /etc/rc.d/init.d/named start
# chkconfig named on
2 、操作檢驗
確認站羣服務器已經正確解析域名或 IP 地址。
# dig ns.linuxde.net.
; <<>> DiG 9.3.4 <<>> ns.linuxde.net.
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54592 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0 ;; QUESTION SECTION: ;ns.linuxde.net.           IN   A ;; ANSWER SECTION: ns.linuxde.net. 86400   IN   A    192.168.0.17 ;; AUTHORITY SECTION: linuxde.net.     86400   IN   NS   ns.linuxde.net. ;; Query time: 0 msec ;; SERVER: 192.168.0.17#53(192.168.0.17) ;; WHEN: Thu Mar 8 19:35:19 2007 ;; MSG SIZE rcvd: 68 # dig -x 192.168.0.17 ; <<>> DiG 9.3.4 <<>> -x 192.168.0.17
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45743 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;17.0.168.192.in-addr.arpa.           IN   PTR ;; ANSWER SECTION: 17.0.168.192.in-addr.arpa. 86400   IN   PTR   ns.linuxde.net. ;; AUTHORITY SECTION: 0.168.192.in-addr.arpa.     86400   IN   NS     ns.linuxde.net. ;; ADDITIONAL SECTION: ns.linuxde.net.          86400   IN   A       192.168.0.17 ;; Query time: 0 msec ;; SERVER: 192.168.0.17#53(192.168.0.17) ;; WHEN: Thu Mar 8 19:37:50 2007 ;; MSG SIZE rcvd: 107 配置從 DNS 站羣服務器 配置從 DNS 站羣服務器比較簡單。下面的例子主 DNS 是 “ns.linuxde.net”,從 DNS 是 “ns.example.info” 。 1 、在主 DNS 站羣服務器的 zone 檔案作如下配置 # vim /var/named/linuxde.net.wan $TTL 86400 @ IN SOA ns.linuxde.net. root.linuxde.net. ( # update serial 2007041501 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) IN NS ns.linuxde.net. # add name server IN NS ns.example.info. IN A 172.16.0.82 IN MX 10 ns.linuxde.net. ns IN A 172.16.0.82 # rndc reload server reload successful 2 、配置從 DNS 站羣服務器 # vim /etc/named.conf # add these lines below zone “linuxde.net” IN { type slave; masters { 172.16.0.82; }; file “slaves/linuxde.net.wan”; }; # rndc reload server reload successful # ls /var/named/slaves linuxde.net.wan         # zone file in master DNS has been just transfered 設定別名記錄,如果你想為你的 WordPress 主機設定另一個名稱,在 zone 檔案定義 CNAME 記錄 # vim /var/named/server-Linux.info.wan $TTL 86400 @ IN SOA ns.server-linux.info. root.server-linux.info. ( # update serial 2007041501 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) IN NS ns.server-linux.info. IN A 172.16.0.82 IN MX 10 ns.server-linux.info. ns IN A 172.16.0.82 # aliase IN CNAME server's name ftp IN CNAME ns.server-linux.info. # rndc reload server reload successful 以下是一個整理的主配檔案引數解釋(僅供參考)/**/代表註釋: options { /*OPTIONS 選項用來定義一些影響整個 DNS 站羣服務器的環境,如這裏的 DI RECTORY 用來指定在本檔案指定的檔案的路徑,如這裏的是將其指定到 /var/named 下, 在這裏你還可以指定埠等等。不指定則埠是 53 */ directory "/var/named"; }; // // // a caching only nameserver config // controls { inet 127.0.0.1 allow { localhost; } keys { rndckey; }; }; zone "." IN { //在這個檔案中是用 zone 關鍵字來定義域區的,一個 zone 關鍵字定義一個域區 type hint; /*在這裏 type 型別有三種,它們分別是 master,slave 和 hint 它們的含義分別是: master: 表示定義的是主域名站羣服務器 slave : 表示定義的是輔助域名站羣服務器 hint: 表示是網際互聯網中根域名站羣服務器 */ file "named.ca"; //用來指定具體存放 DNS 記錄的檔案 }; zone "localhost" IN { //定義一具域名為 localhost 的正向區域 type master; file "localhost.zone" ; allow-update { none; }; }; zone "test.net" IN { //指定一個域名為 test.net 的正向區域 type master; file "test.net” allow-update { none;}; }; zone "0.0.127.in-addr.arpa" IN { //定義一個 IP 為 127.0.0.*的反向域區 type master; file "named.local"; allow-update { none; }; }; zone "0.192.168.in-addr.arpa" IN { //定義一個 IP 為 168.192.0.*反向域區 type master; file "168.192.0"; /var/named/test.net 檔案 @ IN SOA linux.test.net. Webmaster.test.net. ( SOA 表示授權開始 /*上面的 IN 表示後面的資料使用的是 INTERNET 標準。而 @則代表相應的域名,如在這裏代表 test.net, 即表示一個域名記錄定義的開始。而 linux.test.net 則是這個域的主域名站羣服務器,而 webmaster.test.net 則是管理員的郵件地址。注意這是郵件地址中用. 來代替常見的郵件地址中的 @. 而 SOA 表示授權的開始 */ 2003012101 ; serial (d. adams) /*本行前面的數字表示配置檔案的修改版本,格式是年月日當日修改的修改的次數,每次修改這個配置檔案時都應該修改這個數字,要不然你所作的修改不會更新到網上的其它 DNS 站羣服務器的資料庫上,即你所做的更新很可能對於不以你的所配置的 DNS 站羣服務器為 DNS 站羣服務器的客户端來説就不會反映出你的更新,也就對他們來説你更新是沒有意義的。 */ 28800 ; refresh /*定義的是以為單位的重新整理頻率 即規定從域名站羣服務器多長時間查詢一個主站羣服務器,以保證從站羣服務器的資料是最新的 */ 7200 ;retry /*上面的這個值是規定了以秒為單位的重試的時間間隔,即當從服務試圖在主站羣服務器上查詢更時,而連線失敗了,則這個值規定了從服務多長時間後再試 */ 3600000 ; expiry /*上面這個用來規定從站羣服務器在向主服務更新失敗後多長時間後清除對應的記錄,上述的數值是以分鐘為單位的 */ 8400 ) /*上面這個資料用來規定緩衝站羣服務器不能與主服務聯絡上後多長時間清除相應的記 錄 */ IN NS linux IN MX 10 linux linux IN A 168.192.0.14 it-test1 IN A 168.192.0.133 www IN CNAME linux /*上面的第一列表示是 WordPress 主機的名字,省去了後面的域。 NS:表示是這個 WordPress 主機是一個域名站羣服務器, A:定義了一條 A 記錄,即 WordPress 主機名到 IP 地址的對應記錄 MX 定義了一郵件記錄 CNAME:定義了對應 WordPress 主機的一個別名 /var/named/168.192.0 @ IN SOA linux.test.net. webmastert.linux.net. ( 1997022700 ; Serial 28800 ; Refresh 14400 ; Retry 3600000 ; Expire 86400 ) ; Minimum IN NS linux.test.net. /*以上的各關鍵字的含義跟 test.net 是相同的 14 IN PTR linux.test.net. 133 IN PTR it-test1.test.net. /* 上面的第一列表示的是 WordPress 主機的 IP 地址。省略了互聯網地址部分。如 14 完整應該是: 168.192.0.14 PTR:表示反向記錄 最後一列表示的是 WordPress 主機的域名。 原文連結:http://www.linuxde.net/2011/11/2000.html