#########1.安装部署dns############

1)安装服务

[root@server yum.repos.d]# yum install bind -y

开启服务并设为开机自启动,关闭防火墙

Screenshot from 2017-11-26 21-38-03.png

服务安装后会生成如下key

Screenshot from 2017-11-26 21-35-11.png

查看key

Screenshot from 2017-11-26 21-35-31.png

[root@server ~]# ss -antlupe | grep named 此命令可查看服务开放端口

Screenshot from 2017-11-26 21-36-02.png

[root@server ~]# cat /etc/services | grep domain  此命令也可查看端口

 

Screenshot from 2017-11-26 21-36-37.png

2)配置文件

#主配置文件:/etc/named.conf

#子配置文件:/etc/name.rfc1912.zones
#数据目录:/var/named

#2.高速缓存dns####################

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

[root@server ~]# systemctl restart named 重启服务

测试:

在客户主机  做好本地解析

Screenshot from 2017-11-25 22-24-35.png

用命令dig

#3.权威dns的正向解析##############################

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

Screenshot from 2017-11-26 21-51-42.png

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

Screenshot from 2017-11-26 21-52-30.png

[root@dns-server ~]# cd /var/named/  切换到数据目录

[root@dns-server named]# ls
data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves

[root@dns-server named]# cp -p named.localhost westos.com.zone 复制(* -p)

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

Screenshot from 2017-11-26 21-55-45.png

[root@dns-server named]# systemctl restart named  重启服务

测试:11主机上

Screenshot from 2017-11-25 22-25-57.png

#4.反向解析#################################

[root@dns-server ~]# vim /etc/named.rfc1912.zones 编写子配置文件

Screenshot from 2017-11-26 22-08-24.png

[root@dns-server named]# cp -p named.loopback westos.com.ptr  复制

[root@dns-server named]# vim westos.com.ptr 编写

Screenshot from 2017-11-26 22-09-03.png

[root@dns-server named]# systemctl restart named  重启服务

测试

  Screenshot from 2017-11-25 22-37-19.png

#5.双向解析#################################

编辑文件

Screenshot from 2017-11-26 22-20-54.png

Screenshot from 2017-11-26 22-21-01.png

记得重启服务  systemctl restart named

生成双向解析的子配置文件

Screenshot from 2017-11-26 22-22-37.png

编辑双向解析的子配置文件

Screenshot from 2017-11-26 22-24-05.png

Screenshot from 2017-11-26 22-24-16.png

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

(11主机为内部)

[root@dns-server named]# systemctl restart named 重启服务

测试

*)本机

Screenshot from 2017-11-26 22-34-48.png

*)11主机

Screenshot from 2017-11-27 10-31-31.png

#6.辅助dns#################

1)辅助dns上安装服务

Screenshot from 2017-11-27 10-37-52.png

[root@dns-slave ~]# systemctl start named    (敲键盘)

[root@dns-slave ~]# systemctl enable named 
ln -s '/usr/lib/systemd/system/named.service' '/etc/systemd/system/multi-user.target.wants/named.service'
[root@dns-slave ~]# systemctl stop firewalld   (关闭防火墙)

[root@dns-slave ~]# vim /etc/named.conf  修改配置文件

Screenshot from 2017-11-27 10-42-46.png

编辑子配置文件

[root@dns-slave ~]# systemctl restart named  重启服务

[root@dns-slave slaves]# cat /etc/resolv.conf  做好本地解析

nameserver 172.25.12.11

2)主dns的设定

[root@dns-server ~]# vim /etc/named.rfc1912.zones.inter 修改子配置文件

Screenshot from 2017-11-27 10-56-58.png

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

[root@dns-server named]# vim westos.com.inter 编辑

Screenshot from 2017-11-27 11-05-10.png

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

Screenshot from 2017-11-27 11-05-44.png

[root@dns-server named]# cat /etc/resolv.conf  本地解析

nameserver 172.25.12.10

#7.dns的远程更新#########################

实验前,先备份

Screenshot from 2017-11-27 15-40-34.png

[root@dns-server named]# vim /etc/named.rfc1912.zones.inter  修改子配置文件

Screenshot from 2017-11-27 15-43-48.png

[root@dns-server named]# systemctl restart named  重启服务

测试:在172.25.1211主机测试

[root@dns-slave slaves]# nsupdate
> server 172.25.12.10
> update add bbs.westos.com 86400 A 1.1.1.3
> send
update failed: SERVFAIL      失败
>

在dns主机上 给数据目录加权限

Screenshot from 2017-11-27 15-53-06.png

测试:

> server 172.25.12.10

> update add bbs.westos.com 86400 A 1.1.1.3       更新成功
> send
>
[root@dns-server named]# systemctl restart named  每做一次更新 重启服务

[root@dns-server named]# ls

data      named.empty      slaves                westos.com.ptr
dynamic   named.localhost  westos.com.inter      westos.com.zone
named.ca  named.loopback   westos.com.inter.jnl   <-------更新后生成

如下文件中也有更新记录

Screenshot from 2017-11-27 15-59-29.png

Screenshot from 2017-11-27 16-09-41.png

[root@dns-slave slaves]# nsupdate

> server 172.25.12.10
> update add lh.westos.com 86400 A 8.8.8.8     #添加 
> send
> server 172.25.12.10
> update delete bbs.westos.com      #删除
> send

在做下面的实验,还原之前的配置,使环境纯净

[root@dns-server named]# rm -fr westos.com.inter westos.com.inter.jnl  还原

[root@dns-server named]# ls
data     named.ca     named.localhost  slaves          westos.com.zone
dynamic  named.empty  named.loopback   westos.com.ptr
[root@dns-server named]# cp -p /mnt/westos.com.inter .

#基于key的################

按照模板制作westos.key

[root@dns-server mnt]# cp -p  /etc/rndc.key /etc/westos.key  注意*-P

[root@dns-server mnt]# ls -ld /etc/westos.key
-rw-r----- 1 root named 77 Nov 25 08:10 /etc/westos.key

[root@dns-server mnt]# dnssec-keygen -a HMAC-MD5 -b 128 -n HOST westos   (敲键盘)

Screenshot from 2017-11-27 16-37-26.png

[root@dns-server mnt]# vim /etc/westos.key

Screenshot from 2017-11-27 16-40-09.png

[root@dns-server mnt]# vim /etc/named.conf  修改主配置文件

Screenshot from 2017-11-27 16-42-18.png

[root@dns-server mnt]# vim /etc/named.rfc1912.zones.inter 修改主配置文件

Screenshot from 2017-11-27 16-44-34.png

Screenshot from 2017-11-27 16-45-01.png

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

测试

[root@dns-slave slaves]# nsupdate
> server 172.25.12.10
> update add lh.westos.com 86400 A 8.8.8.8
> send
update failed: REFUSED              更新失败
>

把钥匙发给允许更新的11主机

Screenshot from 2017-11-27 17-55-02.png

[root@dns-slave mnt]# ls

Kwestos.+157+44847.key  Kwestos.+157+44847.private
[root@dns-slave mnt]# nsupdate -k Kwestos.+157+44847.private
> server 172.25.12.10
> update add lh.westos.com 86400 A 8.8.8.8   更新成功
> send
> quit

Screenshot from 2017-11-27 18-01-36.png

8.ddns ##################################

1)辅助机设置

[root@dns-slave mnt]# hostnamectl set-hostname www.westos.com  修改主机名

编辑文件使动态获取ip

Screenshot from 2017-11-27 18-19-23.png

Screenshot from 2017-11-27 18-22-46.png

并重启网络

Screenshot from 2017-11-27 18-24-27.png

2)dns主机设置

断网实验

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

Screenshot from 2017-11-27 18-39-41.png

安装dhcp服务

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

[root@dns-server ~]# systemctl stop firewalld  (关闭防火墙)

[root@dns-server ~]# systemctl disable firewalld(设置开机不启动)

Screenshot from 2017-11-27 18-48-42.png

[root@dns-server dhcp]# vim dhcpd.conf  编辑配置文件

Screenshot from 2017-11-27 18-50-39.png

  

14 ddns-update-style interim;  14行修改

Screenshot from 2017-11-27 18-51-16.png

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

Screenshot from 2017-11-27 19-04-49.png

Screenshot from 2017-11-27 19-05-21.png

Screenshot from 2017-11-27 19-19-48.png

[root@dns-server named]# systemctl restart named 重启服务

Screenshot from 2017-11-27 11-27-47.png