CentOS 7 搭建DNS服务器

系统环境

系统平台: CentOS 7.3
DNS Server: 192.168.40.88

#更改主机名,写/etc/hosts记录
[root@xagdns network-scripts]# cat /etc/hosts
192.168.40.88   xag.com  --最后添加DNS服务器IP地址和主机名/别名

关闭防火墙

#临时关闭防火墙 
[root@xagdns ~]# systemctl stop firewalld
#永久关闭防火墙
[root@xagdns ~]# systemctl disable firewalld

关闭selinux

临时关闭:
[root@xagdns ~]# setenforce 0

#永久关闭
[root@xagdns network-scripts]# cat /etc/selinux/config
SELINUX=disabled 

#重启系统永久生效
[root@xagdns ~]#  reboot                                    

CentOS下的DNS服务

#在DNS服务器上安装bind软件
[root@xagdns ~]#  yum  -y  install bind*

#启动DNS服务
[root@xagdns ~]#  systemctl start named.service         --启动DNS服务
[root@xagdns ~]#  systemctl enable named.service     --设置为开机启动
#安装 netstat工具
[root@xagdns ~]# yum install net-tools
[root@xagdns network-scripts]# netstat -anlp | grep named
tcp        0      0 192.168.40.88:53        0.0.0.0:*               LISTEN      1116/named          
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      1116/named          
tcp6       0      0 ::1:953                 :::*                    LISTEN      1116/named          
udp        0      0 192.168.40.88:53        0.0.0.0:*                           1116/named          
unix  2      [ ]         DGRAM                    20812    1116/named     

named作为标准的系统服务脚本,通过“systemctl start/restart/stop named.service”的形式可以实现对服务器程序的控制
named默认监听TCP、UDP协议的53端口,以及TCP的953端口:
其中UDP 53端口一般对所有客户机开放,以提供解析服务;
TCP 53端口一般只对特定从域名服务器开放,提高解析记录传输通道;TCP 953端口默认只对本机(127.0.0.1)开放,用于为rndc远程管理工具提供控制通道

配置文件的目录:
没有安装bind-chroot软件包
配置文件为/etc/named.conf
数据文件在/var/named目录下

安装了bind-chroot软件包
配置文件为/var/named/chroot/etc/named.conf --默认没有
数据文件在/var/named/chroot/var/named目录
从上面看到装了bind-chroot,笼环境为/var/named/chroot/

配置文件/etc/named.conf

#修改之前要先进行备份,使用cp -p /etc/named.conf /etc/named.conf.bak2
#命令备份,参数-p表示备份文件与源文件的属性一致。
[root@xagdns network-scripts]# cat /etc/named.conf
options {
    listen-on port 53 { 192.168.40.88; };
    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; };

    recursion yes;
    dnssec-enable no;
    dnssec-validation no;

    /* Path to ISC DLV key */
    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";
=========================================================
[root@xagdns network-scripts]# cat /etc/named.rfc1912.zones
zone "localhost.localdomain" IN {
    type master;
    file "named.localhost";
    allow-update { none; };
};

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

zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
    type master;
    file "named.loopback";
    allow-update { none; };
};

zone "1.0.0.127.in-addr.arpa" IN {
    type master;
    file "named.loopback";
    allow-update { none; };
};

zone "0.in-addr.arpa" IN {
    type master;
    file "named.empty";
    allow-update { none; };
};

zone "xag.com" IN {
        type master;
        file "data/xag.com.zone";
};

编辑正向解析文件

[root@xagdns network-scripts]# cat  /var/named/data/xag.com.zone
$TTL 1D                 
@       IN SOA  @ xag.com. (2017012501 1D 1H 1W 3H )
        NS      @
        A       127.0.0.1
        AAAA    ::1   
XAGDNS         IN A 192.168.40.88
XAG01       IN A 192.168.40.111
XAG02       IN A 192.168.40.121
XAG01-PRI1  IN A 10.0.20.111
XAG01-PRI2  IN A 10.0.30.112
XAG02-PRI1  IN A 10.0.20.121
XAG02-PRI2  IN A 10.0.30.122
XAG01-VIP   IN A 192.168.40.112
XAG02-VIP   IN A 192.168.40.122
XAG-SCAN    IN A 192.168.40.131
XAG-SCAN    IN A 192.168.40.132
XAG-SCAN    IN A 192.168.40.133

serial:序列号。可以供从服务器判断何时获取新数据的,这里我设成今天的日期。更新数据文件必须要更新这个序列号,否则从服务器将不更新
refresh:指定多长时间从服务器要与主服务器进行核对
retry:如果从服务器试图检查主服务器的序列号时,主服务器没有响应,则经过这个时间后将重新进行检查
expire:将决定从服务器在没有主服务器的情况下权威地持续提供域数据服务的时间长短
minimum:高速缓存否定回答的存活时间
SOA记录:每个区仅有一个SOA记录,该区一直延伸到遇见另一个SOA记录为止。SOA记录包括区的名字,一个技术联系人和各种不同的超时值
IN记录:使用“IN”,对应的是internet
A记录:是DNS数据库的核心。一个主机必须为它的每个网络接口得到一条A记录
NS记录:识别对一个区有权威性的服务器(即所有主服务器和从服务器),并把子域委托给其他机构。
MX记录:电子邮件系统就是使用MX记录来更有效的路由邮件。
PTR记录:从IP地址到主机名的反向映射。与A记录一样,必须为每个网络接口有一条PTR记录。

网卡配置

[root@xagdns network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
NAME="ens33"
UUID="5df96389-fddb-411a-8bac-e754b01c6a08"
DEVICE="ens33"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR="192.168.40.88"
GATEWAY="192.168.40.2"
NETMASK="255.255.255.0"
DNS1="192.168.40.88"

# 重启网卡
[root@xagdns network-scripts]# service network restart
Restarting network (via systemctl):                        [  OK  ]

重新DNS服务

[root@xagdns network-scripts]# systemctl  restart  named.service

测试dns

[root@xagdns network-scripts]# nslookup xag01.xag.com
Server:     192.168.40.88
Address:    192.168.40.88#53

Name:   xag01.xag.com
Address: 192.168.40.111

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