【实验说明】Bind是Linux应用非常广泛的DNS服务器,本文将演示bind-9.6.0-P1的版本在Reh Hat Enterprise Linux 4下建立DNS服务器。
【所需软件】
1、VMware Workstation 6.5 英文正式版
2、Red Hat Enterprise 4原版光盘镜像4张
3、Putty 0.60 远程SSH登陆小工具
【实验步骤】
一、安装bind-9.6.0-P1,将下载好的bind-9.6.0-P1.tar.gz解压,然后运行经典的三步安装./configure、make、make install,这里面我们为./configure加一个参数 --sysconfdir=/etc将配置文件指定到/etc目录下,方便管理
[root@localhost ~]# tar zxvf bind-9.6.0-P1.tar.gz
[root@localhost ~]# cd bind-9.6.0-P1
[root@localhost bind-9.6.0-P1]# ./configure --sysconfdir=/etc
[root@localhost bind-9.6.0-P1]#make
[root@localhost bind-9.6.0-P1]#make install
二、配置根域“.”DNS
1、默认情况下,bind是不会自己创建named.conf配置文件的,我们需要手工在/etc目录下建立这个文件
[root@localhost ~]# touch /etc/named.conf
2、编辑主配置文件/etc/named.conf,增加“.”区域
3、建立“.”域的配置文件named.root,首先要建立文件夹/var/named
[root@localhost ~]# mkdir /var/named
[root@localhost ~]# touch /var/named/named.root
4、产生根域内容添加到named.root
[root@localhost ~]# echo "nameserver 202.97.224.69" > /etc/resolv.conf
[root@localhost ~]# dig -t NS .
; <<>> DiG 9.6.0-P1 <<>> -t NS
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4964
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 14
;; QUESTION SECTION:
;. IN NS
;; ANSWER SECTION:
. 6001 IN NS B.ROOT-SERVERS.NET.
. 6001 IN NS L.ROOT-SERVERS.NET.
. 6001 IN NS I.ROOT-SERVERS.NET.
. 6001 IN NS K.ROOT-SERVERS.NET.
. 6001 IN NS C.ROOT-SERVERS.NET.
. 6001 IN NS E.ROOT-SERVERS.NET.
. 6001 IN NS G.ROOT-SERVERS.NET.
. 6001 IN NS F.ROOT-SERVERS.NET.
. 6001 IN NS A.ROOT-SERVERS.NET.
. 6001 IN NS J.ROOT-SERVERS.NET.
. 6001 IN NS H.ROOT-SERVERS.NET.
. 6001 IN NS M.ROOT-SERVERS.NET.
. 6001 IN NS D.ROOT-SERVERS.NET.
;; ADDITIONAL SECTION:
B.ROOT-SERVERS.NET. 490534 IN A 192.228.79.201
F.ROOT-SERVERS.NET. 517187 IN A 192.5.5.241
F.ROOT-SERVERS.NET. 356083 IN AAAA 2001:500:2f::f
E.ROOT-SERVERS.NET. 44076 IN A 192.203.230.10
D.ROOT-SERVERS.NET. 490408 IN A 128.8.10.90
I.ROOT-SERVERS.NET. 6502 IN A 192.36.148.17
J.ROOT-SERVERS.NET. 529597 IN A 192.58.128.30
J.ROOT-SERVERS.NET. 529597 IN AAAA 2001:503:c27::2:30
C.ROOT-SERVERS.NET. 479758 IN A 192.33.4.12
K.ROOT-SERVERS.NET. 517187 IN A 193.0.14.129
K.ROOT-SERVERS.NET. 356083 IN AAAA 2001:7fd::1
L.ROOT-SERVERS.NET. 488586 IN A 199.7.83.42
L.ROOT-SERVERS.NET. 356083 IN AAAA 2001:500:3::42
G.ROOT-SERVERS.NET. 482641 IN A 192.112.36.4
;; Query time: 22 msec
;; SERVER: 202.97.224.69#53(202.97.224.69)
;; WHEN: Sat Mar 21 09:39:13 2009
;; MSG SIZE rcvd: 500
[root@localhost ~]# echo "nameserver 192.5.5.241" > /etc/resolv.conf
[root@localhost ~]# dig -t NS . > /var/named/named.root
[root@localhost ~]# more /var/named/named.root
; <<>> DiG 9.6.0-P1 <<>> -t NS .
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32158
;; flags: qr aa rd; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 15
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;. IN NS
;; ANSWER SECTION:
. 518400 IN NS E.ROOT-SERVERS.NET.
. 518400 IN NS J.ROOT-SERVERS.NET.
. 518400 IN NS B.ROOT-SERVERS.NET.
. 518400 IN NS M.ROOT-SERVERS.NET.
. 518400 IN NS K.ROOT-SERVERS.NET.
. 518400 IN NS G.ROOT-SERVERS.NET.
. 518400 IN NS L.ROOT-SERVERS.NET.
. 518400 IN NS F.ROOT-SERVERS.NET.
. 518400 IN NS D.ROOT-SERVERS.NET.
. 518400 IN NS C.ROOT-SERVERS.NET.
. 518400 IN NS H.ROOT-SERVERS.NET.
. 518400 IN NS I.ROOT-SERVERS.NET.
. 518400 IN NS A.ROOT-SERVERS.NET.
;; ADDITIONAL SECTION:
A.ROOT-SERVERS.NET. 3600000 IN A 198.41.0.4
B.ROOT-SERVERS.NET. 3600000 IN A 192.228.79.201
C.ROOT-SERVERS.NET. 3600000 IN A 192.33.4.12
D.ROOT-SERVERS.NET. 3600000 IN A 128.8.10.90
E.ROOT-SERVERS.NET. 3600000 IN A 192.203.230.10
F.ROOT-SERVERS.NET. 3600000 IN A 192.5.5.241
G.ROOT-SERVERS.NET. 3600000 IN A 192.112.36.4
H.ROOT-SERVERS.NET. 3600000 IN A 128.63.2.53
I.ROOT-SERVERS.NET. 3600000 IN A 192.36.148.17
J.ROOT-SERVERS.NET. 3600000 IN A 192.58.128.30
K.ROOT-SERVERS.NET. 3600000 IN A 193.0.14.129
L.ROOT-SERVERS.NET. 3600000 IN A 199.7.83.42
M.ROOT-SERVERS.NET. 3600000 IN A 202.12.27.33
A.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:503:ba3e::2:30
F.ROOT-SERVERS.NET. 3600000 IN AAAA 2001:500:2f::f
;; Query time: 29 msec
;; SERVER: 192.5.5.241#53(192.5.5.241)
;; WHEN: Sat Mar 21 09:42:19 2009
;; MSG SIZE rcvd: 492
[root@localhost ~]#
5、产生rndc.conf文件,并将后13行内容追加到/etc/named.conf文件中
[root@localhost ~]# rndc-confgen > /etc/rndc.conf
[root@localhost ~]# tail +13 /etc/rndc.conf >> /etc/named.conf
6、修改追加内容后的/etc/named.conf,去掉相应注释
7、修改本机dns为自己
[root@localhost ~]# echo "nameserver 127.0.0.1" > /etc/resolv.conf
8、启动named服务
[root@localhost ~]# named
9、检测是否启动成功
[root@localhost ~]# ps -aux | grep named
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ
root 10273 0.1 1.8 10136 4724 ? Ss 09:47 0:00 named
root 10275 0.0 0.2 5912 684 pts/0 R+ 09:48 0:00 grep named
[root@localhost ~]#
10、测试
三、配置LocalHost区
1、编辑/etc/named.conf,增加localhost区
2、在/var/named下建立named.local文件,并做相应配置
[root@localhost ~]# touch /var/named/named.local
3、测试
四、配置正向区域
1、编辑/etc/name.conf,增加xiaowu.com区
2、在/var/named下建立xiaowu.com.zone文件,并做相应配置
[root@localhost ~]# touch /var/named/xiaowu.com.zone
3、测试