Linux中國

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

1、安裝Bind Chroot DNS 伺服器

[root@centos7 ~]# yum install bind-chroot bind -y

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

[root@centos7 ~]# cp -R /usr/share/doc/bind-*/sample/var/named/* /var/named/chroot/var/named/

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

[root@centos7 ~]# touch /var/named/chroot/var/named/data/cache_dump.db
[root@centos7 ~]# touch /var/named/chroot/var/named/data/named_stats.txt
[root@centos7 ~]# touch /var/named/chroot/var/named/data/named_mem_stats.txt
[root@centos7 ~]# touch /var/named/chroot/var/named/data/named.run
[root@centos7 ~]# mkdir /var/named/chroot/var/named/dynamic
[root@centos7 ~]# touch /var/named/chroot/var/named/dynamic/managed-keys.bind

4、 將 Bind 鎖定文件設置為可寫

[root@centos7 ~]# chmod -R 777 /var/named/chroot/var/named/data
[root@centos7 ~]# chmod -R 777 /var/named/chroot/var/named/dynamic

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

[root@centos7 ~]# 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 解析,你可以將你擁有的域名如這裡所示配置解析。):

[root@centos7 ~]# vi /var/named/chroot/etc/named.conf

-

..
..
zone "example.local" {
    type master;
    file "example.local.zone";
};

zone "0.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.0.zone";
};
..
..

named.conf 完全配置如下:

//
// named.conf
//
// 由Red Hat提供,將 ISC BIND named(8) DNS伺服器 
// 配置為暫存域名伺服器 (用來做本地DNS解析).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
        listen-on port 53 { any; };
        listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        allow-query     { any; };

        /*
         - 如果你要建立一個 授權域名伺服器 伺服器, 那麼不要開啟 recursion(遞歸) 功能。
         - 如果你要建立一個 遞歸 DNS 伺服器, 那麼需要開啟recursion 功能。
         - 如果你的遞歸DNS伺服器有公網IP地址, 你必須開啟訪問控制功能,
           只有那些合法用戶才可以發詢問. 如果不這麼做的話,那麼你的服
           服務就會受到DNS 放大攻擊。實現BCP38將有效抵禦這類攻擊。
        */
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;
        dnssec-lookaside auto;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";

        pid-file "/run/named/named.pid";
        session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
        type hint;
        file "named.ca";
};

zone "example.local" {
    type master;
    file "example.local.zone";
};

zone "0.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.0.zone";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

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

a)創建轉發域

[root@centos7 ~]# vi /var/named/chroot/var/named/example.local.zone

添加如下內容並保存:

;
;       Addresses and other host information.
;
$TTL 86400
@       IN      SOA     example.local. hostmaster.example.local. (
                               2014101901      ; Serial
                               43200      ; Refresh
                               3600       ; Retry
                               3600000    ; Expire
                               2592000 )  ; Minimum

;       Define the nameservers and the mail servers

               IN      NS      ns1.example.local.
               IN      NS      ns2.example.local.
               IN      A       192.168.0.70
               IN      MX      10 mx.example.local.

centos7          IN      A       192.168.0.70
mx               IN      A       192.168.0.50
ns1              IN      A       192.168.0.70
ns2              IN      A       192.168.0.80

b)創建反向域

[root@centos7 ~]# vi /var/named/chroot/var/named/192.168.0.zone

-

;
;       Addresses and other host information.
;
$TTL 86400
@       IN      SOA     example.local. hostmaster.example.local. (
                               2014101901      ; Serial
                               43200      ; Refresh
                               3600       ; Retry
                               3600000    ; Expire
                               2592000 )  ; Minimum

0.168.192.in-addr.arpa. IN      NS      centos7.example.local.

70.0.168.192.in-addr.arpa. IN PTR mx.example.local.
70.0.168.192.in-addr.arpa. IN PTR ns1.example.local.
80.0.168.192.in-addr.arpa. IN PTR ns2.example.local.。

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

[root@centos7 ~]# /usr/libexec/setup-named-chroot.sh /var/named/chroot on
[root@centos7 ~]# systemctl stop named
[root@centos7 ~]# systemctl disable named
[root@centos7 ~]# systemctl start named-chroot
[root@centos7 ~]# systemctl enable named-chroot
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中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    Leave a reply

    您的電子郵箱地址不會被公開。 必填項已用 * 標註

    此站點使用Akismet來減少垃圾評論。了解我們如何處理您的評論數據

    More in:Linux中國