DNS(domain name server)簡(jiǎn)單的講就是域名解析服務(wù)器,是伯克利大學(xué)科研的成果,對(duì)于IP挑戰(zhàn)大家記憶力的時(shí)候,DNS無(wú)疑成了救命稻草,因?yàn)樗男瘦^之前使用的hosts和NIS有了質(zhì)的飛躍,想了解DNS的詳盡知識(shí),大家請(qǐng)去互聯(lián)網(wǎng)上去看啦!
實(shí)驗(yàn)平臺(tái):VM下兩臺(tái)linux centos5.5服務(wù)器,一臺(tái)作為主服務(wù)器(master),另一臺(tái)作為輔助服務(wù)器(slave)
IP規(guī)劃:
主服務(wù)器:192.168.1.193
輔服務(wù)器:192.168.1.195
第一:在主輔服務(wù)器上都要做的設(shè)置
首先就是是安裝DNS套件
[root@localhost ~]# yum -y install bind bind-chroot ypbind bind-utils caching-nameserver
第二:在主服務(wù)器上的設(shè)置(關(guān)鍵)
[root@localhost ~]# cd /var/named/chroot/etc///進(jìn)入主設(shè)置檔案所在的目錄
[root@localhost etc]# cp -p named.caching-nameserver.conf named.conf//制作主配置文件
以下這個(gè)步驟的含義是:每次服務(wù)啟動(dòng)時(shí)默認(rèn)的會(huì)去/etc目錄下去搜索配置文件,做這個(gè)軟連接也是這個(gè)原因。
[root@localhost etc]# ln -s /var/named/chroot/etc/named.conf /etc/named.conf
以下這個(gè)步驟是對(duì)rndc的設(shè)置(借助rndc對(duì)DNS服務(wù)器的管理,可以在不關(guān)閉DNS服務(wù)器的情況下,更新主服務(wù)器做過(guò)的修改)
[root@localhost ~]# rndc-confgen > /etc/rndc.conf//生成rndc的主配置文檔
對(duì)這個(gè)檔案不做任何的修改,只需把DNS需要的部分復(fù)制過(guò)去即可
[root@localhost ~]# vi /etc/rndc.conf
[root@localhost ~]# vi /etc/named.conf//修改主配置文件,主要修改以下列出的部分即可
listen-on port 53 { any; };
forwarders{202.102.240.65;};
allow-query{ any; };
allow-query-cache { any; };
match-clients{ any; };
match-destinations { any; };
###################### rndc-confgen###################
key "rndckey" {
algorithm hmac-md5;
secret "JkZ/MxIb8I58yefvWMkpIw==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndckey"; };
};
############################END ##################
以上這個(gè)步驟就是可以使用#rdnc reload重載配置文件
[root@localhost ~]# vi /etc/named.rfc1912.zones//添加自己的域
zone "ethnicity.com" IN {
type master;
file "named.ethnicity.com";
allow-update { none; };
allow-transfer { 192.168.1.195;};//這就是針對(duì)輔服務(wù)器做的設(shè)置
also-notify { 192.168.1.195; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "named.192.168.1";
allow-update { none; };
allow-transfer { 192.168.1.195;};
also-notify { 192.168.1.195; };
};
以下這個(gè)步驟是建立自己域名的配置文件
[root@localhost named]# cp -p localhost.zone named.ethnicity.com
[root@localhost named]# cp -p named.local named.192.168.1
[root@localhost named]# vi named.ethnicity.com//設(shè)置正解
$TTL86400
@IN SOAdns.ethnicity.com.root.ethnicity.com. (
46; serial (d. adams)
3H; refresh
15M; retry
1W; expiry
1D ); minimum
IN NSdns.ethnicity.com.
@IN MX 10mail.ethnicity.com.
www1IN A192.168.1.195
www2IN A192.168.1.196
www3IN A192.168.1.193
linuxIN CNAMEwww2
[root@localhost named]# vi named.192.168.1//設(shè)置反解
$TTL86400
@INSOAdns.ethnicity.com. root.ethnicity.com.(
1997022700 ; Serial
28800; Refresh
14400; Retry
3600000; Expire
86400 ); Minimum
INNSdns.ethnicity.com.
195INPTRwww1.ethnicity.com.
196INPTRwww2.ethnicity.com.
193INPTRwww3.ethnicity.com.
[root@localhost ~]# vi /etc/resolv.conf
nameserver 192.168.1.193
然后是簡(jiǎn)單的測(cè)試
[root@localhost ~]# /etc/init.d/named restart
[root@localhost ~]# nslookup//以下測(cè)試可知正反解都可以成功
> 192.168.1.195
Server:192.168.1.193
Address:192.168.1.193#53
195.1.168.192.in-addr.arpaname = www1.ethnicity.com.
> www2.ethnicity.com
Server:192.168.1.193
Address:192.168.1.193#53
Name:www2.ethnicity.com
Address: 192.168.1.196
> exit
最后把配置文件同步到輔服務(wù)器上
[root@localhost ~]# scp /var/named/chroot/etc/named.conf 192.168.1.195:/var/named/chroot/etc/
[root@localhost~]#scp /var/named/chroot/etc/named.rfc1912.zones 192.168.1.195:/var/named/chroot/etc/
第二:在輔服務(wù)器上的設(shè)置
[root@localhost ~]# chgrp named /var/named/chroot/etc/named.conf
[root@localhost etc]# ln -s /var/named/chroot/etc/named.conf /etc/named.conf
[root@localhost ~]# vi /etc/named.conf
listen-on port 53 { any; };
forwarders{202.102.240.65;};
allow-query{ any; };
allow-query-cache { any; };
match-clients{ any; };
match-destinations { any; };
[root@localhost ~]# vi /etc/named.rfc1912.zones//添加以下的域
zone "ethnicity.com" IN {
type slave;
file "slaves/named.ethnicity.com";
masters { 192.168.1.193; };
};
zone "1.168.192.in-addr.arpa" IN {
type slave;
file "slaves/named.192.168.1";
masters { 192.168.1.193; };
};
[root@localhost ~]# /etc/init.d/named restart//重啟服務(wù)器就可以看到輔服務(wù)器的配置文件
[root@localhost ~]# ll /var/named/chroot/var/named/slaves/
total 16
-rw-rw-r-- 1 named named 398 Oct 25 07:06 named.192.168.1
-rw-r--r-- 1 named named 466 Oct 25 07:42 named.ethnicity.com
第三:測(cè)試的部分
這個(gè)步驟主要是觀察在主服務(wù)器修改配置文件是,通過(guò)#rndc reload時(shí),輔服務(wù)器數(shù)據(jù)的同步狀況。
[root@localhost named]# vi named.ethnicity.com//在主服務(wù)器域文件內(nèi)添加兩個(gè)CNAME。并且修改46; serial (d. adams)
$TTL86400
@IN SOAdns.ethnicity.com.root.ethnicity.com. (
46; serial (d. adams)
3H; refresh
15M; retry
1W; expiry
1D ); minimum
IN NSdns.ethnicity.com.
@IN MX 10mail.ethnicity.com.
www1IN A192.168.1.195
www2IN A192.168.1.196
www3IN A192.168.1.193
linuxIN CNAMEwww2
wanyanIN CNAMEwww3
ethnicityIN CNAMEwww1
[root@localhost named]# rndc reload
server reload successful
接著在輔服務(wù)器上查看變化,發(fā)現(xiàn)和主服務(wù)器是數(shù)據(jù)同步的。
[root@localhost ~]# cat /var/named/chroot/var/named/slaves/named.ethnicity.com
$ORIGIN .
$TTL 86400; 1 day
ethnicity.comIN SOAdns.ethnicity.com. root.ethnicity.com. (
46; serial
10800; refresh (3 hours)
900; retry (15 minutes)
604800; expire (1 week)
86400; minimum (1 day)
)
NSdns.ethnicity.com.
MX10 mail.ethnicity.com.
$ORIGIN ethnicity.com.
ethnicityCNAMEwww1
linuxCNAMEwww2
wanyanCNAMEwww3
www1A192.168.1.195
www2A192.168.1.196
www3A192.168.1.193
