Zero's Blog

Centos7安装bind-从服务器

系统环境

  • 系统版本: CentOS Linux release 7.1.1503 (Core)
  • 软件安装: bind bind-libs bind-devel bind-utils bind-chroot

安装

1
yum install bind bind-libs bind-devel bind-utils bind-chroot -y

配置

  • 拷贝 bind 相关文件, 准备 bind chroot 环境

    1
    cp -R /usr/share/doc/bind-*/sample/var/named/* /var/named/chroot/var/named/
  • 在 bind chroot 的目录中创建相关文件

    1
    2
    3
    4
    5
    6
    touch /var/named/chroot/var/named/data/cache_dump.db
    touch /var/named/chroot/var/named/data/named_stats.txt
    touch /var/named/chroot/var/named/data/named_mem_stats.txt
    touch /var/named/chroot/var/named/data/named.run
    mkdir /var/named/chroot/var/named/dynamic
    touch /var/named/chroot/var/named/dynamic/managed-keys.bind
  • 变更目录权限

    1
    2
    chown -R named:named /var/named/chroot/var/named/data
    chown -R named:named /var/named/chroot/var/named/dynamic
  • 拷贝 named.conf 配置文件

    1
    cp -p /etc/named.conf /var/named/chroot/etc/named.conf
  • 修改 bind 配置文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    more named.conf
    // Default named.conf generated by install of bind-9.2.4-27.0.1.el4
    options {
    listen-on port 53 { serverip; };
    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";
    version "oOoOo...";
    allow-query { any; };
    recursion no;
    allow-transfer { serverip; };
    pid-file"/run/named/named.pid";
    session-keyfile "/run/named/session.key";
    managed-keys-directory "/var/named/dynamic";
    };
    controls {
    inet 127.0.0.1 allow { localhost; } keys { rndckey; };
    };
    include "/etc/rndc.key";
    logging {
    channel "named_log" {
    file "/var/named/logs/named.log" versions 10 size 5m;
    severity dynamic;
    print-category yes;
    print-severity yes;
    print-time yes;
    };
    channel "query_log" {
    file "/var/named/logs/query.log" versions 10 size 5m;
    severity debug;
    print-severity yes;
    print-time yes;
    };
    category default { named_log; };
    category queries { query_log; };
    };
    zone "." IN {
    type hint;
    file "named.cache";
    };
    zone "czero.cn" IN {
    type slave;
    masters { serverip; };
    file "czero.cn.db";
    };
  • zone 配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    vim /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
  • 启动服务

    1
    2
    3
    4
    5
    /usr/libexec/setup-named-chroot.sh /var/named/chroot on
    systemctl stop named
    systemctl disable named
    systemctl start named-chroot
    systemctl enable named-chroot