实验环境: 系统-->CentOS6.2(32位) bind版本-->bind-9.9.2下载地址:
过程:
(1)安装
[root@Linux1 ~]# ls
bind-9.9.2.tar.gz
[root@Linux1 ~]# tar zxvf bind-9.9.2.tar.gz -C /opt
[root@Linux1 ~]# cd /opt/bind-9.9.2/
[root@Linux1 bind-9.9.2]# ./configure --prefix=/usr/local/bind-9.9.2 -->有信赖性如没安装openssl-devel ,装一下
[root@Linux1 bind-9.9.2]# echo $?
0
[root@Linux1 bind-9.9.2]# make
[root@Linux1 bind-9.9.2]# echo $?
0
[root@Linux1 bind-9.9.2]# make install
[root@Linux1 bind-9.9.2]# echo $?
0
[root@Linux1 bind-9.9.2]# cd /usr/local/bind-9.9.2/
[root@Linux1 bind-9.9.2]# ls
bin etc include lib sbin share var
(2)配置
这里针对chroot机制做简单的配置,跟实际生产环境配置的思路是一致的。
[root@Linux1 bind-9.9.2]# pwd
/usr/local/bind-9.9.2
[root@Linux1 bind-9.9.2]# mkdir chroot --》 这里先创建chroot来作为named的家目录,如果是系统创建用户自动生成家目录,会去copy /etc/skel 下的一些环境配置文件,而这些配置文件在这里是没必要的。
[root@Linux1 bind-9.9.2]# ls
bin chroot etc include lib sbin share var
[root@Linux1 bind-9.9.2]# groupadd named
[root@Linux1 bind-9.9.2]# useradd -s /sbin/nologin -d /usr/local/bind-9.9.2/ -g named named
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists ---》 这里什么提示文件已经存在,没关系的。
[root@Linux1 bind-9.9.2]# passwd -l named
Locking password for user named.
passwd: Success
[root@Linux1 bind-9.9.2]# grep named /etc/passwd
named:x:501:501::/usr/local/bind-9.9.2/:/sbin/nologin
[root@Linux1 bind-9.9.2]# cd chroot/
[root@Linux1 chroot]# mkdir {dev,etc,var/{log,run,named}} -p
[root@Linux1 chroot]# cd dev
[root@Linux1 dev]# ls -lL /dev/zero /dev/null /dev/random
crw-rw-rw-. 1 root root 1, 3 Oct 16 13:46 /dev/null
crw-rw-rw-. 1 root root 1, 8 Oct 16 13:46 /dev/random
crw-rw-rw-. 1 root root 1, 5 Oct 16 13:46 /dev/zero
[root@Linux1 dev]# mknod null c 1 3
[root@Linux1 dev]# mknod random c 1 8
[root@Linux1 dev]# mknod zero c 1 5
[root@Linux1 dev]# ls
null random zero
[root@Linux1 ~]# cd /usr/local/bind-9.9.2/chroot/etc/
创建主配置文件 named.conf ,我个人实验的配置文件内容如下:
options {
listen-on port 53 { any; };
directory "/var/named"; #--》注意:这里是相对路径,即/usr/local/bind-9.9.2/chroot/ 目录下的 /var/named 。这个和后面的dns服务启动时所引用的配置文件是有关联的:/usr/local/bind-9.9.2/sbin/named -u named -c /etc/named.conf -t /usr/local/bind-9.9.2/chroot/ , -c /etc/named.conf 这个路径也是相对路径,即为/usr/local/bind-9.9.2/chroot/etc/named.conf
allow-query { any; };
recursion yes;
};
logging {
channel "named-log" {
file "/var/log/named.log"; #--》 这里也是相对路径。
severity info;
print-time yes;
print-category yes;
};
category queries { named-log; };
};
zone "5617.com" IN {
type master;
file "5617.com.zone";
allow-update { none; };
};
[root@Linux1 etc]# ls
named.conf
[root@Linux1 etc]# cd ../var/named/
[root@Linux1 named]# ls
5617.com.zone
[root@Linux1 named]# cat 5617.com.zone
$TTL 86400
@ IN SOA dns01.5617.com. root (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS dns01.5617.com.
@ IN A 192.168.1.100
dns01 IN A 192.168.1.100
test IN A 192.168.1.200
www IN CNAME dns01
[root@Linux1 chroot]# /usr/local/bind-9.9.2/sbin/named-checkconf /usr/local/bind-9.9.2/chroot/etc/named.conf
[root@Linux1 chroot]# echo $?
0
[root@Linux1 chroot]# /usr/local/bind-9.9.2/sbin/named-checkzone 5617.com /usr/local/bind-9.9.2/chroot/var/named/5617.com.zone
zone 5617.com/IN: loaded serial 0
OK
(3)启动服务:
[root@Linux1 etc]# /usr/local/bind-9.9.2/sbin/named -u named -c /etc/named.conf -t /usr/local/bind-9.9.2/chroot/
[root@Linux1 ~]# ps aux | grep name
named 12770 0.0 1.1 10768 5684 ? Ss 15:30 0:00 /usr/local/bind-9.9.2/sbin/named -u named -c /etc/named.conf -t /usr/local/bind-9.9.2/chroot/
root 12786 0.3 1.5 46016 7772 ? Ssl 15:33 0:00 named
root 12792 0.0 0.1 4328 720 pts/0 S+ 15:33 0:00 grep name
(4)测试:
[root@Linux1 ~]# ifconfig | grep 'inet addr' | grep -v 127.0.0.1 | sed 's; Bcast.*;;' | awk -F':' '{print $2}'
10.10.1.18
[root@Linux1 ~]# cat /etc/resolv.conf
nameserver 10.10.1.18
[root@Linux1 ~]# nslookup 10.10.1.18
Server: 10.10.1.18
Address: 10.10.1.18#53
canonical name = dns01.5617.com.
Name: dns01.5617.com
Address: 192.168.1.100
[root@Linux1 ~]# nslookup dns01.5617.com 10.10.1.18
Server: 10.10.1.18
Address: 10.10.1.18#53
Name: dns01.5617.com
Address: 192.168.1.100
[root@Linux1 ~]# cat /usr/local/bind-9.9.2/chroot/var/log/named.log
16-Oct-2012 07:24:43.103 queries: client 10.10.1.18#43367 (): query: IN A + (10.10.1.18)
16-Oct-2012 07:24:53.958 queries: client 10.10.1.18#34658 (dns01.5617.com): query: dns01.5617.com IN A + (10.10.1.18)
(5)开机自动启动:
[root@Linux1 ~]# echo '/usr/local/bind-9.9.2/sbin/named -u named -c /etc/named.conf -t /usr/local/bind-9.9.2/chroot/' >> /etc/rc.local
以上是个简单的配置过程,主要就是注意named.conf 中路径的问题。
阅读(3877) | 评论(0) | 转发(0) |