由 ygl 在 10-14-2004 11:27 发表:
BIND9下设置chroot的问题!!!
一 操作环境
Redhat Linux Enterprise U3,BIND9.2.4。
二 操作步骤
1. 安装bind软件包,列表:
bind-libs-9.2.4-EL3_10
bind-devel-9.2.4-EL3_10
bind-utils-9.2.4-EL3_10
bind-9.2.4-EL3_10
bind-chroot-9.2.4-EL3_10
caching-nameserver-7.2-7
2. 准备chroot环境
登录作为root, chroot目录结构
/chroot
+--dev
+--etc
| +--named
+--run
+--var
| +--named
| +--slaves
| +--run
| +--tmp
mknod /chroot/dev/null c 1 3
cp -a /etc/localtime /chroot/etc
修改/etc/rc.d/init.d/syslog 中的 start部分改daemon为下面的行
daemon syslogd $SYSLOGD_OPTIONS -a /chroot/dev/log
然后用/etc/rc.d/init.d/syslog restart重启syslogd后台。
3. 准备rndc 配置文件
rndc是BIND的管理程序,可以用来启动,停止和重新装入配置文件等等。
下面的命令生成hmac-md5键。
/usr/sbin/dnssec-keygen -a hmac-md5 -b 128 -n user rndc
这将生成两个包括密码的文件,把密钥串放入文件rndc.conf和named.conf中。
然后修改/etc/rndc.conf中相应部分成下面的
options {
default-server localhost;
default-key "rndckey";
};
server localhost {
key "rndckey";
};
key rndckey {
algorithm "hmac-md5";
secret
"8voiw4i4nGqaoyqrM91sHQ==";
};
4. 准备named.conf配置文件
用下面的配置文件,内部网络使用192.168.1.0/24。
acl ournets { 127.0.0.1;192.168.1.0/24 };
options {
directory "/etc/named";
pid-file "/var/run/named.pid";
statistics-file "/var/run/named.stats";
/*
If there is a firewall between you and nameservers you want
to talk to, you might need to uncomment the query-source
directive below. Previous versions of BIND always asked
questions using port 53, but BIND 8.1 uses an unprivileged
port by default.
*/
// query-source address * port 53;
allow-recursion { ournets; };
};
controls {
inet 127.0.0.1 allow { localhost; } keys { rndc_key; };
};
//
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
key "rndckey" {
algorithm hmac-md5;
secret "8voiw4i4nGqaoyqrM91sHQ==";
};
zone "0.168.192.IN-ADDR.ARPA" {
type master;
file "192.168.0";
};
zone "domain.com" {
type master;
file "named.domain";
};
5. 准备启动named
放named.conf到/chroot/etc/named.conf
放相应的数据文件到/chroot/etc/named/
拷贝系统自身的几个文件/etc/named.conf,/var/named/* 和自己编辑的
两个文件到192.168.1和named.domain到上面的目录中。
运行命令/usr/sbin/ntsysv去掉自动启动的named前面的标记,然后放下面的行
到/etc/rc.d/rc.local
/usr/local/sbin/named -u named -t /chroot -c /etc/named.conf
6. 目录的属性和所有者权限
chown named:named /chroot/var/run
named后台需要写pid到上面的目录,所有需要设置目录权限给用户named.
chown named:named /chroot
chmod 700 /chroot
让其它用户不可以进入该目录。
7. 启动named
运行下面的命令启动named
/usr/sbin/named -u named -t /chroot -c /etc/named.conf
(无任何提示)
#/usr/sbin/rndc -s localhost reload #重装配置文件,错误提示: rndc: connect failed: connection refused
#/usr/sbin/rndc -s localhost stop #停止named后台,错误提示: rndc: connect failed: connection refused
#/usr/sbin/rndc -s localhost stats #倾倒统计文件,错误提示: rndc: connect failed: connection refused
最后用ps ax(named没有启动)和/usr/sbin/tcpdump port 53 -n检查named是否已处于服务状态中(不在服务状态,就是没有启动)。
++++++++++++++++++++++++++++++++++
不知道出了什么原因,我感觉是目录权限问题,但是以不知道怎么处理!
由 faint 在 10-14-2004 13:50 发表:
chown named.named -R试试chroot下bind的目录。
确保配置文件都没有写错吧。另外,我看bind-chroot你那样做得那么简单吧。比如,这些步骤。
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/bind/etc/localtime
chown named.named -R /etc/bind/etc/bind
chown named.named /etc/bind/var/run
mknod /etc/bind/dev/null c 1 3
mknod /etc/bind/dev/random c 1 8
chmod 666 /etc/bind/dev/null
chmod 644 /etc/bind/dev/random
我看不是能少的。
我用的系统是Debian,bind9是运行正常。但说实在,我还不能确定bind是到底是是在在chroot工作的呢?搞不清。。。
以前不久有讨论,顶置了不久,但也是不了了之哦。
呵呵,我觉得,你先在实在的环境中测试bind9,没有问题才到chroot中试,这样才能把问题弄清楚在那里出错了。
由 ygl 在 10-14-2004 14:13 发表:
多谢!!!
由 ygl 在 10-14-2004 15:26 发表:
/chroot还有bind目录!!!???
由 faint 在 10-14-2004 17:16 发表:
有什么奇怪的啊。系统不同,目录是常有的事情吧。
由 ygl 在 10-15-2004 09:08 发表:
呵呵
由 ygl 在 10-15-2004 09:28 发表:
重新安装以下包
1.bind-libs-9.2.4-EL3_10 #系统盘CD2
2.bind-utils-9.2.4-EL3_10 #系统盘CD2
3.bind-9.2.4-EL3_10 #系统盘CD3
4.caching-names