關(guān)于主輔dns建立的一些心得
關(guān)于主輔dns 建立的一些心得一、在RHEL5上檢查構(gòu)建DNS 所需的安裝包[root@ns1 ~]# rpm -qa |grep bind*bind-utils-9.3.3-7.el5 #提供對D
關(guān)于主輔dns 建立的一些心得
一、在RHEL5上檢查構(gòu)建DNS 所需的安裝包
[root@ns1 ~]# rpm -qa |grep bind*
bind-utils-9.3.3-7.el5 #提供對DNS 服務(wù)器的測試用的工具,如nslookup,dig 等 bind-chroot-9.3.3-7.el5 #為bind 提供一個(gè)偽裝根目錄以增強(qiáng)安全性
bind-9.3.3-7.el5 #構(gòu)建DNS 的主要程序包
[root@ns1 ~]# rpm -qa |grep caching-name*
caching-nameserver-9.3.3-7.el5 #為實(shí)現(xiàn)緩存DNS 服務(wù)器提供必要的配置文件
BIND 的主配置文件為named.conf ,RHEL5和Centos5.5的/etc和/var/named/chroot/etc下默認(rèn)沒有此文件,需要手動(dòng)建立,也可以從/usr/share/doc/bind-9.3.3/sample/etc/下復(fù)制BIND 的主配置樣本文件到/var/named/chroot/etc下。
named.conf 配置文件中主要包括全局配置和區(qū)域配置部分,全局配置部分包括在"options { };"的大括號(hào)中;而區(qū)域配置參數(shù)在"zone { };"中。
二、為提高域名解析效率,需要將主從DNS 的地址寫入到/etc/hosts,同時(shí)在
/etc/resolv.conf文件中指定主從DNS 地址。
[root@ns1 named]# cat /etc/hosts #將主從DNS 地址寫入到hosts 文件中
# Do not remove the following line, or various programs
# that require network functionality will fail.
192.10.10.5 ns1.tgh.com ns1
192.10.10.55 ns2.tgh.com ns2
,[root@ns1 named]# cat /etc/resolv.conf #將主從DNS 地址寫入到resolv.conf 文件中 search tgh.com
nameserver 192.10.10.5
nameserver 192.10.10.55
[root@ns1 ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=ns1.tgh.com #設(shè)置主機(jī)名
GATEWAY=192.10.10.1
三、手動(dòng)創(chuàng)建BIND 主配置文件
[root@ns1 ~]#vi /var/named/chroot/etc/named.conf #使用vi 創(chuàng)建并編輯BIND 主配置文件named.conf
#全局配置參數(shù)
options {
listen-on port 53 { any; }; #設(shè)定監(jiān)聽端口號(hào)、IP 地址;若注釋此行,則在所有的可用IP 地址上監(jiān)聽服務(wù),any 為監(jiān)聽所有
directory "/var/named/"; #此行不能注釋,指定區(qū)域數(shù)據(jù)庫文件存放位置
allow-query { any; }; #允許DNS 查詢的客戶端地址,any 表示所有都可查詢
recursion yes; #設(shè)置允許遞歸查詢
};
#區(qū)域配置參數(shù)
zone "." IN { #設(shè)置根區(qū)域
,type hint; #區(qū)域類型,hint 表示根域、master 表示主域、slave 表示輔助域
file "named.ca"; #對應(yīng)的根域地址數(shù)據(jù)庫文件名
};
zone "tgh.com" IN { #設(shè)置正向DNS 區(qū)域名稱
type master; #區(qū)域類型為主域
file "tgh.com.zone"; #正向區(qū)域的地址數(shù)據(jù)庫文件名
allow-transfer { 192.10.10.55; }; #設(shè)置允許下載區(qū)域數(shù)據(jù)庫信息的從域名服務(wù)器地址 (這個(gè)地方是自己添加的,里面的地址是從DNS 服務(wù)器的IP)
allow-update { none; }; #設(shè)置允許動(dòng)態(tài)更新的客戶端地址為禁止 };
zone "10.10.192.in-addr.arpa" IN { #設(shè)置反向DNS 區(qū)域名稱
type master; #區(qū)域類型為主域
file "192.10.10.arpa"; #反向區(qū)域的地址數(shù)據(jù)庫文件名
allow-transfer { 192.10.10.55;}; #設(shè)置允許下載區(qū)域數(shù)據(jù)庫信息的從域名服務(wù)器地址
allow-update { none; };
};
:wq! #保存退出!
[root@ns1 etc]#chmod 755 named.conf #給予相關(guān)權(quán)限,不然在啟動(dòng)named 時(shí)會(huì)報(bào)錯(cuò)
[root@ns1 etc]# ll named.conf #查看區(qū)域配置文件的屬性
-rwxr-xr-x 1 root root 780 Nov 24 07:37 named.conf
[root@ns1 ~]# named-checkconf /var/named/chroot/etc/named.conf #檢查主配置文件是否存在語法錯(cuò)誤,注意指定路徑哦
,四、手動(dòng)創(chuàng)建BIND 的區(qū)域數(shù)據(jù)庫配置文件
[root@ns1 ~]# vi /var/named/chroot/var/named/tgh.com.zone #創(chuàng)建正向區(qū)域數(shù)據(jù)庫文件,注意文件名及路徑
$TTL 86400 #設(shè)置有效地址解析記錄的默認(rèn)緩存時(shí)間
@ IN SOA tgh.com. admin.tgh.com. ( #設(shè)置SOA 標(biāo)記、域名、域管理郵箱
2010112001 #更新序列號(hào),用于標(biāo)記地址數(shù)據(jù)庫的變化,可以是10位以內(nèi)的整數(shù)
4H #刷新時(shí)間,從域名服務(wù)器更新該地址數(shù)據(jù)庫文件的間隔時(shí)間
15M #重試時(shí)間,從域名服務(wù)器更新地址數(shù)據(jù)庫失敗后,等待多長時(shí)(15 Minutes)間再次嘗試
1W #失效時(shí)間,超過該時(shí)間(1 Week)仍無法更新地址數(shù)據(jù)庫,則不再嘗試
1D #設(shè)置無效地址解析記錄的默認(rèn)緩存時(shí)間(1 Day) )
@ IN NS ns1.tgh.com. #NS為域名服務(wù)器記錄,用于設(shè)置當(dāng)前域的DNS 服務(wù)器的域名地址,注意名稱后都有"."
@ IN NS ns2.tgh.com.
IN MX 5 mail.tgh.com. #MX郵件交換記錄,用于設(shè)置當(dāng)前域的郵件服務(wù)器域名地址,數(shù)字表優(yōu)先級(jí),越大越低
ns1 IN A 192.10.10.5 #A地址記錄,用于記錄正向域名解析
ns2 IN A 192.10.10.55
www IN A 192.10.10.5
www IN A 192.10.10.4 #此處假設(shè)一個(gè)域名對應(yīng)多個(gè)IP ,可以實(shí)現(xiàn)基于DNS 解析的負(fù)載均衡
,mail IN A 192.10.10.5
ftp IN A 192.10.10.5
sz IN CNAME www #CNAME別名記錄,表示sz.tgh.com 是www.tgh.com 的別名,可以通過nslookup sz.tgh.com查看到
* IN A 192.10.10.5 #當(dāng)一個(gè)IP 對應(yīng)大量不同域名時(shí),用作泛域名解析 :wq! #保存退出!
[root@ns1 ~]# vi /var/named/chroot/var/named/192.10.10.arpa #創(chuàng)建反向區(qū)域數(shù)據(jù)庫文件,注意文件名及路徑
$TTL 86400
@ IN SOA tgh.com. admin.tgh.com. (
2010112001
4H
15M
1W
1D
)
@ IN NS ns1.tgh.com. #注意名稱后有"."
@ IN NS ns2.tgh.com.
5 IN PTR ns1.tgh.com.
55 IN PTR ns2.tgh.com.
5 IN PTR www.tgh.com . #PTR指針記錄,第一列為主機(jī)地址
4 IN PTR www.tgh.com . #此處對應(yīng)正向區(qū)域數(shù)據(jù)庫中的假設(shè)一個(gè)域名對應(yīng)多個(gè)IP
5 IN PTR mail.tgh.com.
5 IN PTR ftp.tgh.com .
,:wq! #保存退出!
五、給予相關(guān)權(quán)限,啟動(dòng)named 服務(wù),并關(guān)閉防火墻
[root@ns1 named]# chmod 755 tgh.com.zone #給予相關(guān)權(quán)限
[root@ns1 named]# chmod 755 192.10.10.arpa #給予相關(guān)權(quán)限
[root@ns1 ~]# service named restart #重新啟動(dòng)named 服務(wù)
Stopping named: [ OK ] Starting named: [ OK ]
[root@ns1 etc]# service iptables stop #關(guān)閉防火墻,不然客戶端不能正常解析 Flushing firewall rules: [ OK ] Setting chains to policy ACCEPT: filter [ OK ] Unloading iptables modules: [ OK ]
[root@ns1 ~]# chkconfig --level 35 named on #將named 服務(wù)設(shè)為開機(jī)自啟動(dòng)
[root@ns1 ~]# chkconfig --list named #查看是否在3 5開啟
named 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@ns1 data]# netstat -anp |grep :53 #查看named 端口狀態(tài)
六、驗(yàn)證主域名服務(wù)器
[root@ns1 ~]# nslookup #啟用nslookup 查詢
> www.tgh.com
Server: 192.10.10.5
Address: 192.10.10.5#53
Name: www.tgh.com
Address: 192.10.10.5
,> mail.tgh.com
Server: 192.10.10.5
Address: 192.10.10.5#53
Name: mail.tgh.com
Address: 192.10.10.5
> sz.tgh.com
Server: 192.10.10.5
Address: 192.10.10.5#53
sz.tgh.com canonical name = www.tgh.com .
Name: www.tgh.com
Address: 192.10.10.5
> 192.10.10.5 #反向解析
Server: 192.10.10.5
Address: 192.10.10.5#53
5.10.10.192.in-addr.arpa name = ftp.tgh.com .
5.10.10.192.in-addr.arpa name = ns1.tgh.com.
5.10.10.192.in-addr.arpa name = www.tgh.com .
5.10.10.192.in-addr.arpa name = mail.tgh.com.
在客戶端XP_client上(注:客戶端的DNS 應(yīng)該為192.10.10.5)
C:Documents and Settingstghfly>nslookup www.tgh.com #正向解析 Server: ftp.tgh.com
Address: 192.10.10.5
,Name: www.tgh.com
Address: 192.10.10.5
C:Documents and Settingstghfly>nslookup sz.tgh.com #對設(shè)置的別名進(jìn)行正向解析 Server: ftp.tgh.com
Address: 192.10.10.5
Name: www.tgh.com
Address: 192.10.10.5
Aliases: sz.tgh.com
C:Documents and Settingstghfly>nslookup 192.10.10.5 #反向解析
Server: mail.tgh.com
Address: 192.10.10.5
Name: www.tgh.com
Address: 192.10.10.5
----------------------------------------------------------------------------------------------------
七、在Centos5.5上使用bind 構(gòu)建輔助域名服務(wù)器
注:這個(gè)輔DNS 服務(wù)器,dns 要設(shè)置成自己的,要是把的DNS 地址也指向主DNS 的ip 的話,那等主DNS 掛了,它自己不能解析,因?yàn)樗腄NS 地址不是它自己的。
它要關(guān)防火墻
1、同樣設(shè)置好主機(jī)名、/etc/hosts 、/etc/resolv.conf文件
,[root@ns2 network-scripts]# cat /etc/resolv.conf nameserver 192.10.10.5
nameserver 192.10.10.55
[root@ns2 network-scripts]# cat /etc/hosts
# Do not remove the following line, or various programs # that require network functionality will fail. 192.10.10.5 ns1.tgh.com
192.10.10.55 ns2.tgh.com
[root@ns2 network-scripts]# cat /etc/sysconfig/network NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=ns2.tgh.com
GATEWAY=192.10.10.1
2、在輔助域名服務(wù)器上建立BIND 主配置文件named.conf
[root@ns2 ~]# vi /var/named/chroot/etc/named.conf options {
allow-query { any; };
directory "/var/named";
recursion yes;
};
zone "tgh.com" IN {
type slave; #使用輔助區(qū)域類型
masters { 192.10.10.5; }; #指定主域名服務(wù)器的IP 地址
,這是自己添加的一行,里面的地址是主DNS 的ip
file "slaves/tgh.com.zone"; #從主域名服務(wù)器上下載的地址數(shù)據(jù)庫文件保存到輔助域名服務(wù)器的slaves 目錄下
};
zone "10.10.192.in-addr.arpa" IN {
type slave;
masters { 192.10.10.5; };
file "slaves/192.10.10.arpa";
};
:wq! #保存退出
3、給予相關(guān)權(quán)限,啟動(dòng)named 服務(wù),并關(guān)閉防火墻
[root@ns2 ~]# chmod 755 /var/named/chroot/etc/named.conf
[root@ns2 ~]# service named restart
Stopping named: [ OK ] Starting named: [ OK ]
[root@ns2 ~]# service iptables stop
Flushing firewall rules: [ OK ] Setting chains to policy ACCEPT: nat filter [ OK ] Unloading iptables modules: [ OK ]
[root@ns2 ~]# chkconfig --level 35 named on
[root@ns2 ~]# tail -f /var/log/messages #查看區(qū)域數(shù)據(jù)庫文件下載記錄 Nov 27 14:37:18 ns2 named[5463]: zone tgh.com/IN: Transfer started.
Nov 27 14:37:18 ns2 named[5463]: transfer of 'tgh.com/IN' from 192.10.10.5#53: