DNS服务器搭建示例

DNS服务器搭建示例

负责解析magedu.com域名,能够对一些主机名进行正向解析和逆向解析

  • 配置主配置文件
    [root@slave1 etc]# vim /etc/named.conf
    options {
            listen-on port 53 { 192.168.91.132; };
    //      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     { localhost; };
            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";
    };
    
    logging {
            channel default_debug {
                    file "data/named.run";
                    severity dynamic;
            };
    };
    
    zone "." IN {
            type hint;
            file "named.ca";
    };
    
    zone "magedu.com" IN {
            type master;
            file "magedu.com.zone";
    }
    
    zone "91.168.192.in-addr.arpa" IN {
            type master;
            file "192.168.91.zone";
    };
    include "/etc/named.rfc1912.zones";
    include "/etc/named.root.key";
  • 配置正向区域和反向区域
    [root@slave1 etc]# cd /var/named/
    [root@slave1 named]# cp named.localhost magedu.com.zone
    
    [root@slave1 named]# vim magedu.com.zone
    $TTL 86400
    $ORIGIN magedu.com.
    @       IN SOA  @ dnsadmin.magedu.com. (
                                            2017090901      ; serial
                                            1H      ; refresh
                                            10M     ; retry
                                            3D      ; expire
                                            1D )    ; minimum
            IN  NS  slave1
    ns1  IN      A     192.168.91.132
    web  IN      A     192.168.91.133
    
    [root@slave1 named]# cp  magedu.com.zone  192.168.91.zone
    [root@slave1 named]# vim 192.168.91.zone
    $TTL 86400
    $ORIGIN 91.168.192.in-addr.arpa.
    @       IN SOA  @ dnsadmin.magedu.com. (
                                            2017090901      ; serial
                                            1H      ; refresh
                                            10M     ; retry
                                            3D      ; expire
                                            1D)     ; minimum
            IN  NS  ns1.magedu.com.
    132  IN     PTR    ns1.magedu.com.
    136  IN     PTR    web.magedu.com.
  • 检查语法错误
    [root@slave1 named]# named-checkconf
    [root@slave1 named]# named-checkzone magedu.com /var/named/magedu.com.zone
    [root@slave1 named]# named-checkzone  91.168.192.in-addr.arpa /var/named/192.168.91.zone
  • 权限及属组修改
    [root@slave1 named]# chown :named magedu.com.zone
    [root@slave1 named]# chmod o=  magedu.com.zone
    [root@slave1 named]# chown :named /var/named/192.168.91.zone
    [root@slave1 named]# chmod o= /var/named/192.168.91.zone
  • 启动和验证
    [root@slave1 named]# systemctl  reload  named.service 
    [root@slave1 named]#  dig -t A web.magedu.com @192.168.91.132
    ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.4 <<>> -t A web.magedu.com @192.168.91.132
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26812
    ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
    
    ;; QUESTION SECTION:
    ;web.magedu.com.                        IN      A
    
    ;; ANSWER SECTION:
    web.magedu.com.         86400   IN      A       192.168.91.133
    
    ;; AUTHORITY SECTION:
    magedu.com.             86400   IN      NS      ns1.magedu.com.
    
    ;; ADDITIONAL SECTION:
    ns1.magedu.com.         86400   IN      A       192.168.91.132
    
    ;; Query time: 0 msec
    ;; SERVER: 192.168.91.132#53(192.168.91.132)
    ;; WHEN: Sun Sep 10 00:46:48 2017
    ;; MSG SIZE  rcvd: 82
    
    [root@slave1 named]# dig -x 192.168.91.136 @192.168.91.132
    
    ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.4 <<>> -x 192.168.91.136 @192.168.91.132
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2153
    ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
    
    ;; QUESTION SECTION:
    ;136.91.168.192.in-addr.arpa.   IN      PTR
    
    ;; ANSWER SECTION:
    136.91.168.192.in-addr.arpa. 86400 IN   PTR     web.magedu.com.
    
    ;; AUTHORITY SECTION:
    91.168.192.in-addr.arpa. 86400  IN      NS      ns1.magedu.com.
    
    ;; ADDITIONAL SECTION:
    ns1.magedu.com.         86400   IN      A       192.168.91.132
    
    ;; Query time: 0 msec
    ;; SERVER: 192.168.91.132#53(192.168.91.132)
    ;; WHEN: Mon Sep 11 01:20:59 2017
    ;; MSG SIZE  rcvd: 107

子域授权(cdn)

  • 在magedu.com域对应的服务器上执行
    [root@slave1 named]# vim magedu.com.zone
    $TTL 86400
    $ORIGIN magedu.com.
    @       IN SOA  @ dnsadmin.magedu.com. (
                                            2017090901      ; serial
                                            1H      ; refresh
                                            10M     ; retry
                                            3D      ; expire
                                            1D)     ; minimum
            IN  NS  ns1
    ns1  IN         A     192.168.91.132
    web  IN      A     192.168.91.133
    cdn  IN   NS   ns1.cdn
    ns1.cdn IN  A   192.168.91.134
  • 在cdn.magedu.com域对应的服务器上执行
    [root@master etc]# vim named.conf
    options {
            listen-on port 53 { 192.168.91.134; };
    //      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     { localhost; };
    
            /*
             - 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 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";
    };
    
    zone "cdn.magedu.com" IN {
            type master;
            file "cdn.magedu.com.zone"
    
    };
    include "/etc/named.rfc1912.zones";
    include "/etc/named.root.key";
    [root@master named]# cp named.localhost cdn.magedu.com.zone
    [root@master named]# vim cdn.magedu.com.zone
    $TTL 1D
    $ORIGIN cdn.magedu.com.
    @       IN SOA  @ dnsadmin.cdn.magedu.com. (
                                            2017090901      ; serial
                                            1H      ; refresh
                                            10M     ; retry
                                            1D      ; expire
                                            2H)     ; minimum
            IN  NS  ns1
    ns1  IN   A     192.168.91.134
    www  IN   A     192.168.91.135
    
    [root@master named]# named-checkconf  /etc/named.conf
    [root@master named]# named-checkzone cdn.magedu.com  /var/named/cdn.magedu.com.zone
    
    [root@master named]# chown :named cdn.magedu.com.zone
    [root@master named]# chmod o= cdn.magedu.com.zone
  • 验证
    [root@master named]# dig -t A wwws.cdn.magedu.com @192.168.91.134
    ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.62.rc1.el6_9.4 <<>> -t A web.magedu.com @192.168.91.132
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51054
    ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
    
    ;; QUESTION SECTION:
    ;web.magedu.com.                        IN      A
    
    ;; ANSWER SECTION:
    web.magedu.com.         86400   IN      A       192.168.91.133
    
    ;; AUTHORITY SECTION:
    magedu.com.             86400   IN      NS      ns1.magedu.com.
    
    ;; ADDITIONAL SECTION:
    ns1.magedu.com.         86400   IN      A       192.168.91.132
    
    ;; Query time: 1 msec
    ;; SERVER: 192.168.91.132#53(192.168.91.132)
    ;; WHEN: Sun Sep 10 03:55:14 2017
    ;; MSG SIZE  rcvd: 82

主从服务器(之前配置的两台中,授权子域cdn.magedu.com那台当做从服务器)

  • 配置从区域
    [root@master etc]# vim named.conf
    zone "magedu.com" IN {
            type slave;
            file "slaves/magedu.com.zone";
            masters {192.168.91.132;};
            allow-transfer  { none; };
    
    };
    
    [root@master etc]# named-checkconf
  • 修改主服务器配置
    [root@slave1 named]# vim named.conf
    zone "magedu.com" IN {
            type master;
            file "magedu.com.zone";
            allow-transfer { 192.168.91.134; };
    };
    [root@slave1 named]# vi magedu.com.zone
    $TTL 86400
    $ORIGIN magedu.com.
    @       IN SOA  @ dnsadmin.magedu.com. (
                                            2017090901      ; serial
                                            1H      ; refresh
                                            10M     ; retry
                                            3D      ; expire
                                            1D)     ; minimum
            IN  NS  ns1
            IN  NS  ns2
    ns1  IN         A     192.168.91.132
    ns2  IN         A     192.168.91.134
    web  IN      A     192.168.91.133
  • 主服务器重载配置文件
    [root@slave1 named]#  systemctl reload named.service
  • 从服务器检查配置文件并重启服务
    [root@master etc]# systemctl restart named.service
  • 服务启动后,会在/var/named/slaves/自动添加magedu.com.zone文件
    [root@master slaves]# ls -l
    total 4
    -rw-r--r--. 1 named named 305 Sep 10 01:40 magedu.com.zone

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/87282

(0)
N27_xiaoniN27_xiaoni
上一篇 2017-09-16 20:13
下一篇 2017-09-17 13:12

相关推荐

  • N26 第二周

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。  [1]mkdir : make directories            mkdir [OPTION]… DIRECTORY… &n…

    Linux干货 2017-02-05
  • linux文本编辑利器-vim

    概述 Vim是从vi发展出来的一个文本编辑器。代码补全、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用,和Emacs并列成为类Unix系统用户最喜欢的文本编辑器。Vim强大的编辑能力中很大部分是来自于其普通模式命令。vim的设计理念是命令的组合。例如普通模式命令"dd"删除当前行,"dj"代表删除到下一行…

    Linux干货 2016-08-11
  • 编译安装dropbear

    ssh协议的另一个实现:dropbear 编译安装dropbear [root@centos6 ~]# tar xf dropbear-2013.58.tar.bz2  [root@centos6 ~]# cd dropbear-2013.58 [root@centos6&nbs…

    Linux干货 2016-09-28
  • linux中管道重定向

    linux中管道重定向 Linux 给程序提供三种I/O设备:    查看是否成功  echo $?      需要再执行命令后直接使用               &n…

    Linux干货 2017-02-21
  • 由tty命令产生的好玩的想法

    昨天看了马哥Linux视频的前两天内容,里面讲了到终端的概念,回顾一下:  物理终端:是直接接入本机的显示器和键盘设备。/dev/console  虚拟终端:附加在物理终端之上的以软件方式虚拟实现的终端,CentOS 6默认启动6个虚拟终端 Ctrl+Alt+F#: [1,6] 图形终端:附加在物理终端之上的以软件方式…

    Linux干货 2016-05-16
  • mount命令使用详解

    一、挂载(mount)初识     1.什么是挂载         将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此目录作为其它文件访问入口的行为。     2.常用的文件系统类型 &…

    Linux干货 2016-09-01