搭建DNS服务器主从密钥认证
DNS主从密钥认证
设定:
192.168.3.71 主DNS
192.168.3.72 从DNS
1、首先需要同步时间
yum install -y ntpdate
ntpdate ntp.aliyun.com
2、在主服务器上生成密钥,进行主从秘钥认证
dnssec-keygen -a hmac-md5 -b 128 -n HOST abc
命令说明:
-a hmac-md5:采用hmac-md5加密算法。
-b 128:生成的密钥长度为128位。
-n 密钥类型。我们选择主机类型:HOST 。
-n <nametype>: ZONE | HOST | ENTITY | USER | OTHER
(DNSKEY generation defaults to ZONE)
abc #为生成密钥的名字
创建秘钥对:
cd /var/named/
dnssec-keygen -a hmac-md5 -b 128 -n HOST abc
查看秘钥:# cat Kabc.+157+63226.private
Private-key-format: v1.3
Algorithm: 157 (HMAC_MD5)
Key: DicmtZYSUiZN8BFxuli6jg==
记住key的值:DicmtZYSUiZN8BFxuli6jg== ,从服务器我们也要用该值进行通信秘钥
3、修改配置文件:
主配置文件:
vim /etc/named.conf 修改者几行内容:
13 listen-on port 53 { any; }; 14 listen-on-v6 port 53 { any; }; 21 allow-query { any; }; 33 recursion yes; 新增37行内容: 35 dnssec-enable yes; 36 dnssec-validation yes; 37 dnssec-lookaside auto; 新增如下内容: #新增秘钥abckey 59 key abckey { 60 algorithm hmac-md5; 61 secret "DicmtZYSUiZN8BFxuli6jg=="; 62 }; #新增域名longtao.com的解析 64 zone "longtao.com" IN { 65 type master; 66 file "longtao.com.zone"; 67 allow-transfer { key abckey; }; 68 };
修改后效果如图:
新增秘钥和域名longtao.com截图如下:
主DNS新建域名longtao.com的解析文件
vim /var/named/longtao.com.zone
$TTL 1D @ IN SOA dns.longtao.com. root.longtao.com. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum @ NS dns.longtao.com. dns.longtao.com. A 192.168.3.71 @ A 192.168.3.71 www.longtao.com. A 192.168.3.72 lt.longtao.com. A 119.29.200.236 cname.longtao.com. CNAME www.longtao.com.
修改后截图如下:
从主配置文件:
vim /etc/named.conf 修改者几行内容:
13 listen-on port 53 { any; }; 14 listen-on-v6 port 53 { any; }; 21 allow-query { any; }; 33 recursion yes; #新增37行内容: 35 dnssec-enable yes; 36 dnssec-validation yes; 37 dnssec-lookaside auto; #新增如下内容: 59 key abckey { 60 algorithm hmac-md5; 61 secret "DicmtZYSUiZN8BFxuli6jg=="; 62 }; 63 64 zone "longtao.com" IN { 65 type slave; 66 file "slaves/longtao.com.zone.slave"; 67 masters { 192.168.3.71 key abckey; }; 68 };
修改完成截图如下:
新增秘钥和域名longtao.com解析截图如下:
4、重启服务并测试
先重启master服务器在重启slave服务器:
systemctl restart named
查看slave服务器文件是否同步生成文件:
ll /var/named/slaves/longtao.com.zone.slave
查看文件生成时间是刚刚创建成功,且文件不为空。
查看系统日志显示:
tail -f -n 30 /var/log/messages
最后几行可以看出已经同步成功。
Aug 28 23:18:30 CentOS7 named[12037]: zone longtao.com/IN: transferred serial 0: TSIG 'abckey' Aug 28 23:18:30 CentOS7 named[12037]: transfer of 'longtao.com/IN' from 192.168.3.71#53: Transfer status: success Aug 28 23:18:30 CentOS7 named[12037]: transfer of 'longtao.com/IN' from 192.168.3.71#53: Transfer completed: 1 messages, 8 records, 291 bytes, 0.001 secs (291000 bytes/sec) Aug 28 23:18:31 CentOS7 named[12037]: network unreachable resolving './DNSKEY/IN': 2001:500:9f::42#53 Aug 28 23:18:31 CentOS7 named[12037]: network unreachable resolving './DNSKEY/IN': 2001:503:c27::2:30#53 Aug 28 23:18:31 CentOS7 named[12037]: resolver priming query complete