重点:1)系统是ubuntu的16.04 bind9.10.3
2)确保你的系统是没问题的,我之前的16.04有问题,在虚拟机上怎么都操作都不行,
在/var/log/syslog可以看到:could not load the shared library:dso_lib.c:233类似的信息,
原因应该是openssl库的问题。下面第6条有解决方法。
3)ubuntu16.04使用apt-get 下载的是bind9.10.3,在ubuntu18.04中下载的是bind9.11.3
对bind9.10.3,需要在chroot的文件放置libgost.so到特定位置,这是bind9.10的缺陷,正常情况
对于库的加载应该是在进入chroot之前完成,此处有人探讨:https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=820974
1.安装bind9
sudo apt-get install bind9
2.启动bind9测试一下
sudo /etc/init.d/bind9 restart
观察bind是否可以启动
sudo vim /var/log/syslog
如果在现在的启动时间下出现:
May 29 09:03:46 yy-pc named[36284]: running
表示 named 已经启动,可以正常启动,下面开始配置chroot的启动
3.修改/etc/bind/named.conf.options :
sudo vim /etc/bind/named.conf.options
开头处:
options {
directory "/var/cache/bind";
dnssec-validation auto;
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
};
chroot的路径是 /var/cache/bind
把这个文件内容修改为
options {
listen-on port 53 { any; };
directory "/var/cache/bind";
dump-file "/var/cache/bind/data/cache_dump.db";
statistics-file "/var/cache/bind/data/named_stats.txt";
memstatistics-file "/var/cache/bind/data/named_mem_stats.txt";
allow-query { any; };
recursion yes;
forward only;
forwarders {
8.8.8.8;
8.8.4.4;
};
};
4.修改chroot的目录,使它可以让bind运行起来
cd /var/cache/bind
在这里创建目录 dev etc/bind run/named usr var/cache/bind var/run/named
mknod /var/cache/bind/dev/null c 1 3
mknod /var/cache/bind/dev/random c 1 8
chmod 660 /var/cache/bind/dev/{null,random}
将bind的默认配置文件移动到目标地址:mv /etc/bind /var/bind9/chroot/etc
为了保持兼容性,仍在原位置为其建立软链: ln -s /var/bind9/chroot/etc/bind /etc/bind
5. 设置配置文件:
修改/etc/default/bind9 : OPTIONS="-u bind" --> OPTIONS="-u bind -t /var/cache/bind"
修改/etc/init.d/bind9 : PIDFILE=/run/named/named.pid --> PIDFILE=/var/cache/bind/run/named/named.pid
6. 重新启动bind9:
sudo /etc/init.d/bind9 restart
提示:[ ok ] Restarting bind9 (via systemctl): bind9.service.
q千万不要被假象迷惑!!!!
查看syslog
sudo vim /var/log/syslog
最后几行出错:
ENGINE_by_id failed (crypto failure)
Jun 23 01:29:04 yy-pc named[57416]: error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:233:
Jun 23 01:29:04 yy-pc named[57416]: error:260B6084:engine routines:DYNAMIC_LOAD:dso not found:eng_dyn.c:467:
Jun 23 01:29:04 yy-pc named[57416]: error:2606A074:engine routines:ENGINE_by_id:no such engine:eng_list.c:390:id=gost
Jun 23 01:29:04 yy-pc named[57416]: initializing DST: crypto failure
Jun 23 01:29:04 yy-pc named[57416]: exiting (due to fatal error)
Jun 23 01:29:04 yy-pc systemd[1]: bind9.service: Main process exited, code=exited, status=1/FAILURE
Jun 23 01:29:04 yy-pc rndc[57437]: rndc: connect failed: 127.0.0.1#953: connection refused
Jun 23 01:29:04 yy-pc systemd[1]: bind9.service: Control process exited, code=exited status=1
Jun 23 01:29:04 yy-pc systemd[1]: bind9.service: Unit entered failed state.
Jun 23 01:29:04 yy-pc systemd[1]: bind9.service: Failed with result 'exit-code'.
这是因为缺少必要的库文件,复制关键库文件到chroot的对应目录即可,具体操作在7.
7. 复制库文件到chroot
(1)创建库文件路径
cd /var/cache/bind
sudo mkdir -p /var/cache/bind/usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines
源文件目录:/usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines/libgost.so
目标目录:/var/cache/bind/usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines/libgost.so
下划线是你chroot的目录。如果复制了之后,还是无法解决,
可以问题应该出在: a. openssl不对劲 b. 系统可以有点儿问题(我虚拟机系统不对, 硬盘上的是可以解决的) c.放弃bind9.10
友情链接,均由参考:
http://www.snooda.com/read/290
https://www.howtoforge.com/howto_bind_chroot_debian