Linux下dns服务器搭建

时间:2021-12-14 06:21:13

Linux下dns服务器搭建
1-环境
Red Hat Enterprise Linux Server release 6.7 (Santiago)
2-配置本地yum源安装dns相关包
yum -y install bind bind-chroot bind-utils
chkconfig named on
service named restart
3-修改相关配置文件
 1- 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; };
   allow-query-cache {any; };//添加此行
   allow-transfer {any; };//添加此行

forwarders {202.106.0.20; 210.51.176.71; 202.136.251.1; }; //添加转发

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";
 };

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";
 2- 修改vim /etc/named.rfc1912.zones
 添加下面两行信息
 zone "fengge.com" IN {
   type master;
   file "fengge.com.zone";
   allow-transfer {any;};
 };

zone "14.168.192.in-addr.arpa" IN {
   type master;
   file "14.168.192.zone";
   allow-transfer {any;};
 };
 3- 配置fengge.com.zone、14.168.192.zone文件
  cp named.localhost fengge.com.zone
  cp named.localhost 14.168.192.zone
  vim fengge.com.zone
 $TTL 86400
 @       IN SOA  nagios.fengge.com. root (
           0       ; serial
           1D      ; refresh
           1H      ; retry
           1W      ; expire
           3H )    ; minimum
 @       IN      NS      nagios.fengge.com.

//优先级:0-99,数字越小级别越高
 @       IN      MX 5(优先级)    mail.fengge.com.
 @       IN      A       192.168.14.222
 nagios  IN      A       192.168.14.222
 mail    IN      A       192.168.14.222
 pop     IN      A       192.168.14.222
 pop3    IN      A       192.168.14.222
 vim 14.168.192.zone
 $TTL 86400
 @       IN SOA  nagios.fengge.com. root (
           12      ; serial
           28800   ; refresh
           14400   ; retry
           3600000 ; expire
           86400 ) ; minimum
 @       IN      NS      nagios.fengge.com.
 222     IN      PTR     mail.fengge.com.

SOA(Start Of Authority):起始授权记录,用于标明一个区域内部主从服务器之间如何同步数据,起始授权对象是谁的

ZONE NAME TTL IN SOA 主DNS服务器地址(FQDN) ADMINISTRATOR MAILBOX  (serial number

                          refresh

                          retry

                          expire

                          na ttl)

NS(Name Server):ZONE NAME--->FQDN

MX(Mail exchanager):ZONE NAME--->FQDN

A (address): FQDN---->IPV4

AAAA:FQDN--->IPV6

PTR(pointer):IP--->FQDN

CNAME(Canoical NAME):FQDN--->FQDN

  www2.magedu.com.   IN   CNAME  www.magedu.com

www2.mageduc.om//别名

区域传送的类型:

   完全区域传送:axfr

   增量区域传送:ixfr

区域类型:

   主区域:master

   从区域:slave

提示区域:hint 定义根在哪里,找不到的都告诉根在哪里

转发区域:forward
 4- 配置/etc/resolve.conf文件
 server 127.0.0.1   
 search fengge.com
 //添加上面两行信息
 chmod +r /var/named/*

//一定要授权不然会出错。
4-测试
service  named restart
nslookup
> 127.0.0.1
Server:         127.0.0.1
Address:        127.0.0.1#53

1.0.0.127.in-addr.arpa  name = localhost.

> nagios.fengge.com
Server:         127.0.0.1
Address:        127.0.0.1#53

Name:   nagios.fengge.com
Address: 192.168.14.222
> nagios.fengge.com
Server:         127.0.0.1
Address:        127.0.0.1#53

Name:   nagios.fengge.com
Address: 192.168.14.222

> 192.168.14.222
Server:         127.0.0.1
Address:        127.0.0.1#53

222.14.168.192.in-addr.arpa     name = mail.fengge.com.

至此正向解析、和反向解析都解析完毕

备注:windows清dns缓存命令

ipconfig /flushdns

搭建主从dns服务器的时候报Oct 15 09:36:20 logclient1 named[9249]: dumping master file: slaved/tmp-MBaX6MOlPc: open: file not found
总结可能出现问题的原因有两条:
1-权限问题

/etc/named.conf /etc/named.rfc1912.zone /var/named/slaves

2-配置路径问题

/etc/named.rfc1912

zone "xingxing.com" IN {
        type slave;
        file "slaves/xingxing.com.zone";
        masters { 192.161.14.222; };
//      allow-transfer { none; };
};

zone "14.161.192.in-addr.arpa" IN {
        type slave;
        file "slaves/14.161.192.zone";
        masters { 192.161.14.222; };
//        allow-transfer { none; };
};

3-主从同步配置文件

注意要配置从服务器的NS记录