CentOS中bind服务搭建和配置

安装bind

yum -y install bind bind-utils

修改name.conf文件

文件位置 /etc/named.conf

    options {
        listen-on port 53 { any; };   //将127.0.0.1改为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";

        forwarders {119.29.29.29;182.254.116.116;};  //添加此行内容,当内网无法解析时,用外网解析

        allow-query     { any; };  //将localhost改为any

        recursion yes;  //递归查询改为no

        dnssec-enable no;    //将yes改为no

        dnssec-validation no;   //将yes改为no

        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";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

修改named.rfc1912.zones

备份原文件

修改named.rfc1912.zones文件


vim /etc/named.rfc1912.zones

文件未尾加入如下域名zone配置代码

zone "meilis.cn" IN {    
    type master;           
    file "meilis.cn.zone";
    allow-update { none; };
};

创建meilis.cn.zone文件

cp -p /var/named/named.localhost /var/named/meilis.cn.zone

vim meilis.cn.zone

zone文件代码格式如下

$TTL 1D
@ IN SOA dns.meilis.cn. zheng.zurui. (
                1987    ; serial
                1D    ; refresh
                1H    ; retry
                1W    ; expire
                3H )    ; minimum
@    IN    NS    dns
@    IN    NS    ns
dns    IN    A    *.96.72.60
ns    IN    A    *.98.60.92
*    IN    A    *.96.72.60
*    IN    A    *.98.60.92
@    IN    CNAME    meilis.cn.w.kunlunaq.com.
www    IN    CNAME    www.meilis.cn.w.kunlungr.com.
oss    IN    CNAME    oss.meilis.cn.w.kunlunca.com.
gravatar    IN    CNAME    gravatar.meilis.cn.w.kunlungr.com.

检查配置文件是否正确

named-checkconf

named-checkzone meilis.cn /var/named/meilis.cn.zone

启动bind服务

systemctl start named
systemctl enable named

重新加载配置

如果修改配置文件,不需要重启bind服务,直接重新加载即可

rndc reload

注意事项

meilis.cn.zone 文件给与777权限
开启服务器的UDP&TCP 53端口
设置和增加域名的DNS服务器IP

解析结果生效测试

Last modification:August 15th, 2021 at 03:16 pm
如果觉得我的文章对你有用,请随意赞赏