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

相关推荐

  • 文件系统挂载

    文件系统挂载 文件系统管理: 将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此目录做为其它文件访问入口的行为称之为挂载;  解除此关联关系的过程称之为卸载;  把设备关联挂载点:Mount Point mount  卸载时:可使用设备,也可以使用挂载点 umount  注意:挂载点下原有文件在挂载完成后…

    Linux干货 2015-12-16
  • Linux的命令使用格式

    ◆Linux命令格式:command [options]  [arguments]command:命令options:  –单词   或   -单字如: ls –allequ      ls -als -a -b -cequ&…

    Linux干货 2016-10-31
  • 马哥教育N22期第四周作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 root@xuc-virtual-machine:/home/xuc# cp -r /etc/skel/ /home/tuser1 root@xuc-virtual-machine:/…

    Linux干货 2016-09-06
  • 网络管理

    7层结构。三次握手,四次挥手。

    2017-12-17
  • M20 – 1- 第二周(2):课堂练习与作业

    课堂练习: 1、显示/var目录下所有以l开头,以一个小写字母结尾,且中间出现至少一位数字的文件和目录 [root@centos6 ~]# ls /var/l*[[:digit:]]*[[:lower:]] ls: cannot access /var/l*[[:digit:]]*[[:lower:…

    Linux干货 2016-08-02
  • DNS实验

    正向解析 编辑/etc/named.conf listen-on port 53 { 172.0.0.1; 192.168.209.134; }; //listen-on-v6 port 53 { ::1; }; allow-query { any; }; dnssec-enable no; dnssec-validation no; 编辑/etc/name…

    Linux干货 2017-05-31