【实验说明】Bind是Linux应用非常广泛的DNS服务器,本文将演示bind-9.6.0-P1的版本在Reh Hat Enterprise Linux 4下建立DNS服务器。
![](https://i-blog.csdnimg.cn/blog_migrate/e4a40ac34bbcb2d8b2fbbba0c48d76cf.png)
三、配置LocalHost区
【所需软件】
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
[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,增加“.”区域
![](https://i-blog.csdnimg.cn/blog_migrate/aaacf5a3548a8b41acc92490a0dbd46d.png)
3、建立“.”域的配置文件named.root,首先要建立文件夹/var/named
[root@localhost ~]# mkdir /var/named
[root@localhost ~]# touch /var/named/named.root
[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 .
[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
;; 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
;. 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.
. 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
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
;; 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
;; 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
;. 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.
. 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
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
;; 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文件中
5、产生rndc.conf文件,并将后13行内容追加到/etc/named.conf文件中
[root@localhost ~]# rndc-confgen > /etc/rndc.conf
[root@localhost ~]# tail +13 /etc/rndc.conf >> /etc/named.conf
[root@localhost ~]# tail +13 /etc/rndc.conf >> /etc/named.conf
6、修改追加内容后的/etc/named.conf,去掉相应注释
![](https://i-blog.csdnimg.cn/blog_migrate/ce1eaf5063c5beb8a2697b05b163c585.png)
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 ~]#
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、测试
![](https://i-blog.csdnimg.cn/blog_migrate/e4a40ac34bbcb2d8b2fbbba0c48d76cf.png)
三、配置LocalHost区
1、
编辑/etc/named.conf,增加localhost区
![](https://i-blog.csdnimg.cn/blog_migrate/6421a3412ab47e3282a615c0e67a7a56.png)
2、
在
/var/named下建立named.local文件,并做相应配置
[root@localhost ~]# touch /var/named/named.local
![](https://i-blog.csdnimg.cn/blog_migrate/4d68301480465091eb27e3594e440e39.png)
3、
测试
![](https://i-blog.csdnimg.cn/blog_migrate/c0d32282de6bad4dc6a7c74d1d7cd28f.png)
四、
配置正向区域
1、
编辑
/etc/name.conf,增加xiaowu.com区
![](https://i-blog.csdnimg.cn/blog_migrate/b404f15a46b1a65f292c740b3ea69562.png)
2、在
/var/named下建立xiaowu.com.zone文件,并做相应配置
[root@localhost ~]# touch /var/named/xiaowu.com.zone
![](https://i-blog.csdnimg.cn/blog_migrate/6e1f27e4857be57190b5778993da31e1.png)
3、
测试
![](https://i-blog.csdnimg.cn/blog_migrate/15c3a3032a9d356d9a560172cc6584a3.png)
本文转自 Jhuster 51CTO博客,原文链接:http://blog.51cto.com/xwnet/142765,如需转载请自行联系原作者