一、安裝html
# yum -y install bind caching-nameserverlinux
二、配置web
下面的例子是以公網IP(172.16.0.80/29),局域網IP(192.168.0.0/24),域名(linuxde.net)做說明。在配置你本身的服務器時,請使用你本身的IP和域名。數據庫
# vim /etc/named.confvim
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
建立zone文件以便服務器能解析域名IP。服務器
一、內部zone文件網絡
這個例子使用的是內網地址(192.168.0.0/24),域名(linuxde.net),請根據本身的具體狀況配置。dom
# vim /var/named/linuxde.net.lanpost
$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
二、外部zone文件this
這個例子使用的是外網地址(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到域名。
三、內部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.
四、外部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的配置後,在啓動named以前,還須要創建chroot環境。
# yum -y install bind-chroot
# /etc/rc.d/init.d/named start
# chkconfig named on
二、操做檢驗
確認服務器已經正確解析域名或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是「ns.linuxde.net」,從DNS是「ns.example.info」。
一、在主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
二、配置從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
設置別名記錄,若是你想爲你的主機設置另外一個名稱,在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
/*上面的第一列表示是主機的名字,省去了後面的域。
NS:表示是這個主機是一個域名服務器,
A:定義了一條A記錄,即主機名到IP地址的對應記錄
MX 定義了一郵件記錄
CNAME:定義了對應主機的一個別名
/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.
/*
上面的第一列表示的是主機的IP地址。省略了網絡地址部分。如14完整應該是:
168.192.0.14
PTR:表示反向記錄
最後一列表示的是主機的域名。