1. 程式人生 > >在 CentOS7.0 上搭建 Chroot 的 Bind DNS 服務器

在 CentOS7.0 上搭建 Chroot 的 Bind DNS 服務器

n) 地址 授權 dns 部分 soa 自啟 named 就會

BIND(Berkeley internet Name Daemon)也叫做NAMED,是現今互聯網上使用最為廣泛的DNS 服務器程序。這篇文章將要講述如何在 chroot 監牢中運行 BIND,這樣它就無法訪問文件系統中除“監牢”以外的其它部分。

例如,在這篇文章中,我會將BIND的運行根目錄改為 /var/named/chroot/。當然,對於BIND來說,這個目錄就是 /(根目錄)。 “jail”(監牢,下同)是一個軟件機制,其功能是使得某個程序無法訪問規定區域之外的資源,同樣也為了增強安全性(LCTT 譯註:chroot “監牢”,所謂“監牢”就是指通過chroot機制來更改某個進程所能看到的根目錄,即將某進程限制在指定目錄中,保證該進程只能對該目錄及其子目錄的文件進行操作,從而保證整個服務器的安全)。Bind Chroot DNS 服務器的默認“監牢”為 /var/named/chroot。

你可以按照下列步驟,在CentOS 7.0 上部署 Bind Chroot DNS 服務器。

技術分享

1、安裝Bind Chroot DNS 服務器

  1. [[email protected] ~]# yum install bind-chroot bind -y

2、拷貝bind相關文件,準備bind chroot 環境

  1. [[email protected] ~]# cp -R /usr/share/doc/bind-*/sample/var/named/* /var/named/chroot/var/named/

3、在bind chroot 的目錄中創建相關文件

  1. [[email protected]
/* */ ~]# touch /var/named/chroot/var/named/data/cache_dump.db
  • [[email protected] ~]# touch /var/named/chroot/var/named/data/named_stats.txt
  • [[email protected] ~]# touch /var/named/chroot/var/named/data/named_mem_stats.txt
  • [[email protected] ~]# touch /var/named/chroot/var/named/data/named.run
  • [[email protected]
  • /* */ ~]# mkdir /var/named/chroot/var/named/dynamic
  • [[email protected] ~]# touch /var/named/chroot/var/named/dynamic/managed-keys.bind
  • 4、 將 Bind 鎖定文件設置為可寫

    1. [[email protected] ~]# chmod -R 777 /var/named/chroot/var/named/data
    2. [[email protected] ~]# chmod -R 777 /var/named/chroot/var/named/dynamic

    5、 將 /etc/named.conf 拷貝到 bind chroot目錄

    1. [[email protected] ~]# cp -p /etc/named.conf /var/named/chroot/etc/named.conf

    6、 在/etc/named.conf中對 bind 進行配置。

    在 named.conf 文件尾添加 example.local 域信息, 創建轉發域(Forward Zone)與反向域(Reverse Zone)(LCTT 譯註:這裏example.local 並非一個真實有效的互聯網域名,而是通常用於本地測試的一個域名;如果你需要做權威 DNS 解析,你可以將你擁有的域名如這裏所示配置解析。):

    1. [[email protected] ~]# vi /var/named/chroot/etc/named.conf

    -

    1. ..
    2. ..
    3. zone "example.local" {
    4. type master;
    5. file "example.local.zone";
    6. };
    7. zone "0.168.192.in-addr.arpa" IN {
    8. type master;
    9. file "192.168.0.zone";
    10. };
    11. ..
    12. ..

    named.conf 完全配置如下:

    1. //
    2. // named.conf
    3. //
    4. // 由Red Hat提供,將 ISC BIND named(8) DNS服務器
    5. // 配置為暫存域名服務器 (用來做本地DNS解析).
    6. //
    7. // See /usr/share/doc/bind*/sample/ for example named configuration files.
    8. //
    9. options {
    10. listen-on port 53 { any; };
    11. listen-on-v6 port 53 { ::1; };
    12. directory "/var/named";
    13. dump-file "/var/named/data/cache_dump.db";
    14. statistics-file "/var/named/data/named_stats.txt";
    15. memstatistics-file "/var/named/data/named_mem_stats.txt";
    16. allow-query { any; };
    17. /*
    18. - 如果你要建立一個 授權域名服務器 服務器, 那麽不要開啟 recursion(遞歸) 功能。
    19. - 如果你要建立一個 遞歸 DNS 服務器, 那麽需要開啟recursion 功能。
    20. - 如果你的遞歸DNS服務器有公網IP地址, 你必須開啟訪問控制功能,
    21. 只有那些合法用戶才可以發詢問. 如果不這麽做的話,那麽你的服
    22. 服務就會受到DNS 放大攻擊。實現BCP38將有效抵禦這類攻擊。
    23. */
    24. recursion yes;
    25. dnssec-enable yes;
    26. dnssec-validation yes;
    27. dnssec-lookaside auto;
    28. /* Path to ISC DLV key */
    29. bindkeys-file "/etc/named.iscdlv.key";
    30. managed-keys-directory "/var/named/dynamic";
    31. pid-file "/run/named/named.pid";
    32. session-keyfile "/run/named/session.key";
    33. };
    34. logging {
    35. channel default_debug {
    36. file "data/named.run";
    37. severity dynamic;
    38. };
    39. };
    40. zone "." IN {
    41. type hint;
    42. file "named.ca";
    43. };
    44. zone "example.local" {
    45. type master;
    46. file "example.local.zone";
    47. };
    48. zone "0.168.192.in-addr.arpa" IN {
    49. type master;
    50. file "192.168.0.zone";
    51. };
    52. include "/etc/named.rfc1912.zones";
    53. include "/etc/named.root.key";

    7、 為 example.local 域名創建轉發域與反向域文件

    a)創建轉發域

    1. [[email protected] ~]# vi /var/named/chroot/var/named/example.local.zone

    添加如下內容並保存:

    1. ;
    2. ; Addresses and other host information.
    3. ;
    4. $TTL 86400
    5. @ IN SOA example.local. hostmaster.example.local. (
    6. 2014101901 ; Serial
    7. 43200 ; Refresh
    8. 3600 ; Retry
    9. 3600000 ; Expire
    10. 2592000 ) ; Minimum
    11. ; Define the nameservers and the mail servers
    12. IN NS ns1.example.local.
    13. IN NS ns2.example.local.
    14. IN A 192.168.0.70
    15. IN MX 10 mx.example.local.
    16. centos7 IN A 192.168.0.70
    17. mx IN A 192.168.0.50
    18. ns1 IN A 192.168.0.70
    19. ns2 IN A 192.168.0.80

    b)創建反向域

    1. [[email protected] ~]# vi /var/named/chroot/var/named/192.168.0.zone

    -

    1. ;
    2. ; Addresses and other host information.
    3. ;
    4. $TTL 86400
    5. @ IN SOA example.local. hostmaster.example.local. (
    6. 2014101901 ; Serial
    7. 43200 ; Refresh
    8. 3600 ; Retry
    9. 3600000 ; Expire
    10. 2592000 ) ; Minimum
    11. 0.168.192.in-addr.arpa. IN NS centos7.example.local.
    12. 70.0.168.192.in-addr.arpa. IN PTR mx.example.local.
    13. 70.0.168.192.in-addr.arpa. IN PTR ns1.example.local.
    14. 80.0.168.192.in-addr.arpa. IN PTR ns2.example.local.。

    8、開機自啟動 bind-chroot 服務

    1. [[email protected] ~]# /usr/libexec/setup-named-chroot.sh /var/named/chroot on
    2. [[email protected] ~]# systemctl stop named
    3. [[email protected] ~]# systemctl disable named
    4. [[email protected] ~]# systemctl start named-chroot
    5. [[email protected] ~]# systemctl enable named-chroot
    6. ln -s ‘/usr/lib/systemd/system/named-chroot.service‘ ‘/etc/systemd/system/multi-user.target.wants/named-chroot.service‘

    via: http://www.ehowstuff.com/how-to-setup-bind-chroot-dns-server-on-centos-7-0-vps/

    作者:skytech 譯者:SPccman 校對:wxy

    本文由 LCTT 原創翻譯,Linux中國 榮譽推出

    在 CentOS7.0 上搭建 Chroot 的 Bind DNS 服務器