首页 > 代码库 > DNS服务器的配置

DNS服务器的配置

实验环境搭建

1.先对desktop,server重置

2.对虚拟机内存进行设置,防止卡机。

技术分享

3.服务端配置

(1)##配置网络

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

  技术分享

[root@localhost ~]# systemctl restart network

(2)##修改服务器名字

[root@localhost ~]# hostnamectl set-hostname dns-server.westos.com

[root@localhost ~]# hostname

dns-server.westos.com

(3)##配置yum源

[root@localhost ~]# vim /etc/yum.repos.d/rhel_dvd.repo 

   技术分享

[root@localhost ~]# ifconfig


  技术分享


(4)##安装DNS

[root@dns-server ~]# yum search dns

[root@dns-server ~]# yum install bind.x86_64 -y

技术分享

技术分享

(5)##配置服务端

[root@dns-server ~]# systemctl stop firewalld

[root@dns-server ~]# ll /etc/rndc.key

[root@dns-server ~]# systemctl start named

[root@dns-server ~]# ll /etc/rndc.key

[root@dns-server ~]# cat /etc/rndc.key

技术分享

[root@dns-server ~]# netstat -antlpe | grep named

技术分享

[root@dns-server ~]# vim /etc/named.conf #编辑配置文件

options {                             ##全局设定

        listen-on port 53 { any; };  ##监听本地53端口

        listen-on-v6 port 53 { ::1; }; ##关闭ipv6选项 

        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; };  ##允许与本地直连的网络使用

        forwarders {172.25.254.250; }  ##指向dns

[root@dns-server ~]# systemctl start named

[root@dns-server ~]# netstat -antlpe | grep named

技术分享

[root@dns-server ~]# cat /dev/random

技术分享

一 正向解析

服务端

[root@dns-server ~]# cd /var/named

[root@dns-server named]# pwd

/var/named

[root@dns-server named]# ls

data     named.ca     named.localhost  slaves

dynamic  named.empty  named.loopback

[root@dns-server named]# cp -p named.localhost westos.com.zone

##用模板生成用模板生成dns配置配置文件

[root@dns-server named]# vim westos.com.zone

技术分享

[root@dns-server named]# vim /etc/named.rfc1912.zones 


zone "westos.com" IN {    #指定要维护的域名

        type master;

        file "westos.com.zone"; ##指定A记录文件名

        allow-update { none; };

};


[root@dns-server named]# systemctl restart named技术分享

客户端

    3  vim /etc/resolv.conf

    4  dig dns.westos.com

    5  dig www.westos.com

技术分享

技术分享

技术分享

二 多向解析

1. 配置网卡

服务端

添加网卡

技术分享

配置网络

48  ifconfig

50  cd /etc/sysconfig/network-scripts/

51  ls

52  cp ifcfg-eth0 ifcfg-eth1

53  ls

54  vim ifcfg-eth1

55  systemctl restart network

56  systemctl restart named

57  netstat -antlpe | grep named

技术分享

2

服务端

15  cd /var/named/

16  ls

20  cp -p westos.com.zone westos.com.inter

21  vim westos.com.inter  

$TTL 1D

@       IN SOA  dns.westos.com. root.westos.com. (

                          ||

                dns服务器的主机名       0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

                NS      dns.westos.com. ##指定dns主机

dns             A       172.25.254.144    ##指定dns服务器的A记录

www             A       172.25.254.244    ##要添加的A记录

music           CNAME   music.a.westos.com.

music.a         A       172.25.254.111

music.a         A       172.25.254.222

westos.com.     MX 1    172.25.254.244.

22  cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.inter

23  vim /etc/named.rfc1912.inter

zone "westos.com" IN {

        type master;

        file "westos.com.inter";

        allow-update { none; };

};

24  vim /etc/named.conf

view localnet  {

                match-clients { 172.25.254.0/24; };##允许网络使用

                zone "." IN {

                type hint;

                file "named.ca";

                };

                include "/etc/named.rfc1912.zones";

};

view internet  {

                match-clients { 172.25.44.0/24; };##允许网络使用

                zone "." IN {

                type hint;

                file "named.ca";

                };

                include "/etc/named.rfc1912.inter";

};



25  man named.conf

26  fg

29  systemctl restart named

49  systemctl status firewalld

50  systemctl stop firewalld

技术分享


技术分享

技术分享


技术分享

3 客户端测试254和44

45  mail root@westos.com

46  mailq

技术分享

(1)172..25.254.144

23  vim /etc/resolv.conf 

24  dig music.westos.com

25 dig -t mx westos.com

技术分享

(2)172.25.44.11

1  vim /etc/resolv.conf

2  dig music.westos.com

3  dig -t mx westos.com

技术分享

技术分享技术分享

三  反向解析

服务器

 58  vim /etc/named.rfc1912.zones

       48 zone "254.25.172.in-addr.arpa" IN {

       49         type master;

       50         file "westos.com.ptr";

       51         allow-update { none; };

       52 };

 59  cp -p named.loopback westos.com.ptr

 60  vim westos.com.ptr

     $TTL 1D

      @       IN SOA  dns.westos.com. root.westos.com. (

                                        0       ; serial

                                        1D      ; refresh

                                        1H      ; retry

                                        1W      ; expire

                                        3H )    ; minimum

             NS      dns.westos.com.

     dns     A       172.25.254.244

     111     PTR     www.westos.com

 61  systemctl restart named

技术分享

技术分享

技术分享

客户端 

dig -x 172.25.254.111.

技术分享

四 dns更新

服务端

更新

[root@dns-server ~]# cp -p /var/named/westos.com.zone /mnt/

[root@dns-server ~]# vim /etc/named.rfc1912.zones


zone "westos.com" IN {     

        type master;

        file "westos.com.zone";

        allow-update { 172.25.254.144; };

};


[root@dns-server ~]# chmod 770 /var/named/

[root@dns-server ~]# setsebool -P named_write_master_zones 1

[root@dns-server ~]# systemctl restart named

技术分享

查看更新

[root@dns-server ~]#  cd /var/named

[root@dns-server named]# vim westos.com.zone

[root@dns-server named]#  systemctl restart named

[root@dns-server named]# vim westos.com.zone技术分享

删除

[root@dns-server named]# rm -fr  westos.com.zone westos.com.zone.jnl 

[root@dns-server named]# cp  -p /mnt/westos.com.zone .

[root@dns-server named]# ll -d

drwxrwx---. 5 root named 4096 May  6 04:17 .

[root@dns-server named]# ls -l

total 32

drwxrwx---. 2 named named   22 May  5 22:09 data

drwxrwx---. 2 named named 4096 May  6 04:10 dynamic

-rw-r-----. 1 root  named 2076 Jan 28  2013 named.ca

-rw-r-----. 1 root  named  152 Dec 15  2009 named.empty

-rw-r-----. 1 root  named  152 Jun 21  2007 named.localhost

-rw-r-----. 1 root  named  168 Dec 15  2009 named.loopback

drwxrwx---. 2 named named    6 Jan 29  2014 slaves

-rw-r-----. 1 root  named  410 May  6 03:35 westos.com.inter

-rw-r-----. 1 root  named  204 May  6 03:53 westos.com.ptr

-rw-r-----. 1 root  named  415 May  5 23:52 westos.com.zone

[root@dns-server named]# systemctl restart named

[root@dns-server named]# vim westos.com.zone

技术分享

客户端

增加

[root@localhost ~]# nsupdate

> server 172.25.254.244

> update add hello.westos.com 86400 A 172.25.254.222

>  send  【ctrl+d】

[root@localhost ~]# dig hello.westos.com

技术分享

删除

[root@localhost ~]# nsupdate

> server 172.25.254.244

> update delete hello.westos.com 86400 A 172.25.254.222

> send 【ctrl+d】

五 加密上传 dnskey update

服务端

[root@dns-server ~]# dnssec-keygen -a HMAC-MD5 -b 32 -n HOST westoskey ##制作钥匙

Kwestoskey.+157+59437

[root@dns-server ~]# ls

anaconda-ks.cfg  Downloads                      Music     Templates

Desktop          Kwestoskey.+157+18814.key      Pictures  Videos

Documents        Kwestoskey.+157+18814.private  Public

2

[root@dns-server ~]# cp -p /etc/rndc.key /etc/westos.key

[root@dns-server ~]# vim /etc/westos.key  ##配置钥匙文件

[root@dns-server ~]# cat /etc/westos.key

key "westoskey" {

algorithm hmac-md5;

secret " HqglOQ==";

};

[root@dns-server ~]# cat Kwestoskey.+157+18814.key

[root@dns-server ~]# cat Kwestoskey.+157+18814.private

3

[root@dns-server ~]# vim /etc/named.conf ##配置DNS

    42 include "/etc/westos.key";

技术分享

[root@dns-server ~]# vim /etc/named.rfc1912.zones

   zone"westos.com" IN {

        type master;

        file "westos.com.zone";

        allow-update { key westoskey; };

    };

[root@dns-server ~]# systemctl restart named

技术分享

4     

[root@dns-server ~]#  scp Kwestoskey.+157+18814.* root@172.25.254.144:/mnt/  ##下放钥匙

技术分享

客户端

[root@localhost ~]# cd /mnt/

[root@localhost mnt]# ls

Kwestoskey.+157+18814.key  Kwestoskey.+157+18814.private 

[root@localhost mnt]#  nsupdate -k Kwestoskey.+157+18814.private

##用钥匙上传

10-May-2017 11:32:55.412 the key ‘westoskey‘ is too short to be secure

> server 172.25.254.244 

> update add hello.westos.com 86400 A 172.25.254.111

> send

> [root@localhost mnt]dig hello.westos.com

技术分享

六 动态

服务端

1

[root@dns-server ~]# yum install dhcp -y  ##安装dhcp

2

[root@dns-server ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y   

[root@dns-server ~]# vim /etc/dhcp/dhcpd.conf  ##配置dhcp文件


    7 option domain-name "westos.com";

    8 option domain-name-servers 172.25.254.244

   14 ddns-update-style interim;

   30 subnet 172.25.254.0 netmask 255.255.255.0  {

   31   range 172.25.254.50 172.25.254.60;

   32   option routers 172.25.254.250;

   33 }

   34 

   35 key westoskey {

   36         algorithm hmac-md5;

   37         secret " HqglOQ==";

   38 };

   39 zone westos.com. {

   40      primary 127.0.0.1;

   41      key westoskey;

   42 }

客户端

[root@localhost ~]# hostnamectl set-hostname test.westos.com

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE=eth0

    BOOTPROTO=dhcp

    ONBOOT=yes

[root@localhost ~]# systemctl restart network

[root@test ~]# icconfig

[root@test ~]# dig test.westos.com

技术分享

技术分享

技术分享

技术分享


DNS服务器的配置