linux搭建DNS服务器

安装服务

yum –y install bind   #安装DNS 服务
yum install bind-utils –y  #安装DNS 检测工具

编辑配置文件

vi /etc/named.conf
options {
        listen-on port 53 { any; };                      #监听地址和端口
        #listen-on-v6 port 53 { any; };        
        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";
        recursing-file  "/var/named/data/named.recursing";
        secroots-file   "/var/named/data/named.secroots";
        allow-query     { any; };                          #允许使用本DNS服务器的网段

        /* 
         - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
         - If you are building a RECURSIVE (caching) DNS server, you need to enable 
           recursion. 
         - If your recursive DNS server has a public IP address, you MUST enable access 
           control to limit queries to your legitimate users. Failing to do so will
           cause your server to become part of large scale DNS amplification 
           attacks. Implementing BCP38 within your network would greatly
           reduce such attack surface 
        */
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.root.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;
        };
};


include "/etc/named.rfc1912.zones";
#include "/etc/named.root.key";            #无法解析外网地址就注释掉这个

检查语法错误

named-checkconf

编辑配置文件

vi /etc/named.rfc1912.zones
zone "ttpark.link" IN {                       #正向"ttpark.link"区域
        type master;                          #类型为主要区域
        file "ttpark.link.zone";              #区域数据文件
        allow-update { none; };
};
zone "1.168.192.in-addr.arpa" in {              #反向"192.168.1.0/24"区域
        type master;
        file "192.168.1.arpa";                  #区域数据文件为 192.168.1.arpa
        allow-update { none; };
};

编写正向DNS配置

cd /var/named
cp -p named.localhost ttpark.link.zone     #编辑正向区域数据配置文件,注意复制配置文件时,要保持源文件权限
vi ttpark.link.zone    //编辑正向区域数据配置文件内容
$TTL 1D
@       IN SOA   ttpark.link.   admin.ttpark.link. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@       IN     NS    ns.ttpark.link.
ns      IN     A    192.168.1.24
eka     IN     A     192.168.1.31
mq      IN     A     192.168.1.22

编辑反向配置文件

cp -p   ttpark.link.zone 192.168.1.arpa   #复制反向区域数据配置文件
vi 192.168.1.arpa
$TTL 1D
@       IN SOA   ttpark.link.  admin.ttpark.link. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@       IN     NS    ns.ttpark.link.             #注意后面的点
240     IN     PTR   ns.ttpark.link.
31      IN     PTR   eka.ttpark.link. 
22      IN     PTR    mq.ttpark.link.

全部配置文件编写完成后可以使用以下命令对所有DNS相关的配置文件进行检查,如有语法错误的地方,会依次指出

[root@localhost named]# named-checkzone 1.168.192.in-addr.arpa /var/named/192.168.1.arpa
zone 1.168.192.in-addr.arpa/IN: loaded serial 0
OK
[root@localhost named]# named-checkzone ttpark.link.zone /var/named/ttpark.link.zone 
zone ttpark.link.zone/IN: loaded serial 0
OK
[root@localhost named]#  named-checkconf -z /etc/named.conf 
zone ttpark.link/IN: loaded serial 0
zone 1.168.192.in-addr.arpa/IN: loaded serial 0

测试DNS服务器

systemcrl restart named    #重新启动服务
vi /etc/resolv.conf      #添加新的DNS  nameserver 192.168.1.24
[root@localhost named]# nslookup ns.ttpark.link    #正向测试
Server:         192.168.1.24
Address:        192.168.1.24#53

Name:   ns.ttpark.link
Address: 192.168.1.24
[root@localhost named]# nslookup 192.168.1.24   #反向测试
24.1.168.192.in-addr.arpa      name = ns.ttpark.link.

你可能感兴趣的:(linux搭建DNS服务器)