Linux:DNS服务器搭建及配置

1、yum install -y bind bind-chroot bind-utils 

2、编辑DNS主配置文件

  vim /etc/named.conf   修改如下标红色处即可:

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 yes;

3、添加域名设置

   vim /etc/named.rfc1912.zones     新增如下内容:

   zone "wsmtstest.com" IN {
        type master;
        file "named.wsmtstest.com";
        allow-update { none; };
};

4、修改域名配置文件

cd /var/named/
cp named.localhost named.wsmtstest.com
vim named.wsmtstest.com(要和主配置文件[/etc/named.rfc1912.zones]里面定义的文件名一致),末尾新增如下内容:

www IN A 115.231.20.100

【表示:www.wsmtstest.com 解析到115.231.20.100】

5、重启服务:service named restart

【注意!域名解析不成功时,查看前面创建的域名配置文件是否有read权限,若没有则进行授权】

 检验域名的解析IP是多少是,可用dig命令,dig www.aa.com +short

-------------------------20190628【另外一组配置示例】---------------------------------------

/etc/name.conf

/named.conf 
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
    listen-on port 53 { any; };  //如果要启动127.0.0.2的监听IP,需要先ip addr add 127.0.0.2 dev lo 才能启动该监听IP,否则默认启动127.0.0.1的
    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";
#    query-source    port 53;    
#    query-source-v6 port 53;
#    allow-query     { localhost;192.168.21.45; };
};
logging {
        channel default_debug {
                file "named_run.log";
        print-time yes;
                severity debug;
        };
category queries {
               default_debug;
              };
};
view localhost_resolver {
    match-clients        { localhost; };
    match-destinations { localhost; };
    recursion yes;
    #include "/etc/named.rfc1912.zones";
    zone "aa.com" IN {
        type master;
        file "aa.com.zone";
        allow-update { none; };
    };
    zone "bb.com" IN {
        type master;
        file "bb.com.zone";
        allow-update { none; };
        };
};

/var/named/aa.com.zone

/aa.com.zone 
$TTL    5
@       IN SOA  @       root (
                                      1997022700 ; Serial
                                      8      ; Refresh
                                      16     ; Retry
                                      24    ; Expire
                                      36 )    ; Minimum
;            IN NS       @
;            IN NS       @
@           IN NS       aaa.
aaa         IN A        127.0.0.11
www         IN A        127.0.0.11
每天努力一点,每天学习一点。 Keep Moving...
原文地址:https://www.cnblogs.com/channy14/p/7086263.html