ubuntu16.04設定bind9.10.3的chroot執行
重點: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
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=820974
https://blog.csdn.net/symptoms216/article/details/7963