dns2

准备工作

1:配置yum源,火墙,下载相关软件。

[root@localhost ~]# hostnamectl set-hostname dns-example.com
[root@localhost ~]# hostname
dns-example.com
[root@localhost ~]# vim /etc/yum.repos.d/rhel_dvd.repo
[root@localhost ~]# yum clean all
Loaded plugins: langpacks
Cleaning repos: rhel_dvd
Cleaning up everything
[root@localhost ~]# yum install dhcp -y
Loaded plugins: langpacks
rhel_dvd                                                 | 4.1 kB     00:00     
(1/2): rhel_dvd/group_gz                                   | 134 kB   00:00     
(2/2): rhel_dvd/primary_db                                 | 3.4 MB   00:00     
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-27.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package       Arch            Version                  Repository         Size
================================================================================
Installing:
 dhcp          x86_64          12:4.2.5-27.el7          rhel_dvd          506 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 506 k
Installed size: 1.4 M
Downloading packages:
dhcp-4.2.5-27.el7.x86_64.rpm                               | 506 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 12:dhcp-4.2.5-27.el7.x86_64                                  1/1 
  Verifying  : 12:dhcp-4.2.5-27.el7.x86_64                                  1/1 

Installed:
  dhcp.x86_64 12:4.2.5-27.el7                                                   

Complete!
[root@localhost ~]# yum install bind -y
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.9.4-14.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package       Arch            Version                  Repository         Size
================================================================================
Installing:
 bind          x86_64          32:9.9.4-14.el7          rhel_dvd          1.8 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 1.8 M
Installed size: 4.3 M
Downloading packages:
bind-9.9.4-14.el7.x86_64.rpm                               | 1.8 MB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 32:bind-9.9.4-14.el7.x86_64                                  1/1 
  Verifying  : 32:bind-9.9.4-14.el7.x86_64                                  1/1 

Installed:
  bind.x86_64 32:9.9.4-14.el7                                                   

Complete!
[root@localhost ~]# vim /etc/named.conf 

这里写图片描述

[root@localhost ~]# vim /etc/named.rfc1912.zones 
[root@localhost ~]# vim /var/named/westos.com.zone

这里写图片描述
这里写图片描述

[root@localhost named]# dig www.westos.com

; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> www.westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44547
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.westos.com.            IN  A

;; ANSWER SECTION:
www.westos.com.     86400   IN  A   172.25.254.100

;; AUTHORITY SECTION:
westos.com.     86400   IN  NS  dns.westos.com.

;; ADDITIONAL SECTION:
dns.westos.com.     86400   IN  A   172.25.254.233

;; Query time: 0 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Wed Aug 09 21:53:28 EDT 2017
;; MSG SIZE  rcvd: 93

1:dns key 更新

1

dnssec-keygen -a HMAC-MD5 -b 128 -n HOST westos ##生成密匙

cat Kwestos.+157+18569.key
westos. IN KEY 512 3 157 4SJx4m33BpJnNpl8slHIWA==

2

cp /etc/rndc.key /etc/westos.key -p ##生成dns的加密文件
vim /etc/westos.key
key “westos” { ##key名称
algorithm hmac-md5;
secret “4SJx4m33BpJnNpl8slHIWA==”; ##key的加密字符
};

[root@localhost ~]# dnssec-keygen -a HMAC-MD5 -b 128 -n HOST westos
Kwestos.+157+12223
[root@localhost ~]# ls
anaconda-ks.cfg  Downloads                   Music     Templates
Desktop          Kwestos.+157+12223.key      Pictures  Videos
Documents        Kwestos.+157+12223.private  Public
[root@localhost ~]# cat Kwestos.+157+12223.key
westos. IN KEY 512 3 157 UWrxBTu6JEGAk6zD4jB4Lg==
[root@localhost ~]# cp -p /etc/rndc.key  /etc/westos.key
[root@localhost ~]# vim /etc/westos.key 

这里写图片描述

3

vim /etc/named.conf
43 include “/etc/westos.key”; ##指定dns服务读取的key文件

vim /etc/named.rfc1913.zones
zone “westos.com” IN {
type master;
file “westos.com.inter”;
allow-update { key westos; }; ##指定westos域可以被westoskey 更新
};
这里写图片描述
这里写图片描述
测试

[root@localhost ~]# ll /var/named/
total 20
drwxrwx---. 2 named named   22 Aug  9 21:53 data
drwxrwx---. 2 named named   30 Aug  9 22:03 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  223 Aug  9 21:53 westos.com.zone
[root@localhost ~]# chmod g+w /var/named/
[root@localhost mnt]# nsupdate -k  Kwestos.+157+12223.private
> server 172.25.254.111
> update add www.westos.com 86400 A 172.25.254.111
> send    
> quit

dhcpd 配置

[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@localhost ~]# vim etc/dhcp/dhcpd.conf 

vim /etc/dhcp/dhcpd.conf
14 ddns-update-style interim; ##开启dhcp更新dns功能

37 key westos { ##dhcp更新dns时用到的key
38 algorithm hmac-md5;
39 secret 4SJx4m33BpJnNpl8slHIWA==;
40 };
41
42 zone westos.com. { ##指定dhcp更新的域名
43 primary 127.0.0.1; ##指定dns所在的主机ip
44 key westos; ##指定更新这个域时用到的key名称
45 }
这里写图片描述
这里写图片描述
这里写图片描述

测试

设定一台主机网络的工作方式为dhcp
设定这台主机的主机名music.westos.com,这个名称在原有的dns服务中是没有解析的
重启网络看ip 和主机名称的解析
这里写图片描述
这里写图片描述
这里写图片描述

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

; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> music.westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63251
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;music.westos.com.      IN  A

;; ANSWER SECTION:
music.westos.com.   300 IN  A   172.25.254.99

;; AUTHORITY SECTION:
westos.com.     86400   IN  NS  dns.westos.com.

;; ADDITIONAL SECTION:
dns.westos.com.     86400   IN  A   172.25.254.233

;; Query time: 1 msec
;; SERVER: 172.25.254.111#53(172.25.254.111)
;; WHEN: Wed Aug 09 23:25:00 EDT 2017
;; MSG SIZE  rcvd: 95

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值