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

相关推荐

  • Linux路由实验

    一    实验背景:路由器的功能是将不同网段的主机建立通信,本次试验是在使用linux主机当作路由器,完成主机间通信。如下图所示 二、实验环境:主机A和B为CentOS7.2,主机C和D为CentOS6.8,且C和D上分别都有两块网卡 三、实验步骤     注意:为避免干扰项,需将每台主机…

    Linux干货 2016-09-07
  • 6个变态的C语言Hello World程序

    下面的六个程序片段主要完成这些事情: 输出Hello, World 混乱C语言的源代码 下面的所有程序都可以在GCC下编译通过,只有最后一个需要动用C++的编译器g++才能编程通过。 hello1.c   #define _________ }     #define …

    Linux干货 2015-04-01
  • Bash的I/O重定向及管道

    每周更新的博客定时派送啦,本周与大家一起分享的是重定向和管道 首先了解一下 读入数据:Input 输出数据:Output 我们来看一下重定向:  >  覆盖重定向 上面图中 > 文件名     创建空文件 touch 文件名 创建空文件 这两种方法都可以创建一个新的文…

    2017-07-21
  • 私人定制-linux系统和grub启动流程中问题及解决方案

    系统的启动流程;     POST加电自检–>Boot Sequence(BIOS)–>Boot Loader(MBR)–>kernel(Ramdisk)–>rootfs–>switchroot–>/sbin/i…

    Linux干货 2016-09-13
  • 磁盘管理之swap,移动设备及dd命令的使用

    首先我们来复习一下前一天的内容 CHS Sector(扇区) 512字节 track(磁道) 63个 2^6个扇区 1024个磁道,10个位存储磁道数 track=cylinder(柱面) cylinder=(容量)sector(512)track(63)head(256)=8M head(磁头) 256 8位存储 MBR的分区方式都是基于柱面为整…

    Linux干货 2016-09-07
  • linux网络管理

    Linux网络配置 摘要:Linux 对网络的管理分为 静态指定和动态管理。 静态指定 静态指定ip一般有命令              ifconfig       &…

    Linux干货 2016-04-05