实验环境: 系统-->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 soadns01.5617.com. root (
0; serial
1d; refresh
1h; retry
1w; expire
3h ); minimum
@innsdns01.5617.com.
@ina192.168.1.100
dns01ina192.168.1.100
testina192.168.1.200
wwwincnamedns01
[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 中路径的问题。
阅读(3820) | 评论(0) | 转发(0) |