root:~ # yum install httpdroot:~ # cd /var/www/html/root:/var/www/html # echo 192.168.64.57,hello >index.htmlroot:/var/www/html # chmod a+r index.htmlroot:/var/www/html # service httpd restart
3客户端测试
4配置主masterDNS
12345678910111213141516171819202122232425262728
root:~ # yum install bindroot:~ # vi /etc/named.conf// listen-on port 53 { 127.0.0.1; };// allow-query { localhost; };allow-transfer {192.168.64.47;}; root:~ # vi /etc/named.rfc1912.zoneszone "qh.com"IN { type master; file "qh.com.zone";};root:~ # cd /var/named/root:/var/named # vi qh.com.zone$TTL 1D@ IN SOA ns1 qh.mail.com. ( 11H 10M 1D 3H ) NS ns1 NS ns2ns1 A 192.168.64.37ns2 A 192.168.64.47www A 192.168.64.57root:/var/named # chgrp named qh.com.zoneroot:/var/named # chmod 640 qh.com.zone#### 语法检查root:/var/named # named-checkconf#### 启动服务root:/var/named # systemctl start named.service
5客户端测试master服务器
img
6搭建从服务器
12345678910111213141516
root:~ # yum install bindroot:~ # vi /etc/named.conf// listen-on port 53 { 127.0.0.1; };// allow-query { localhost; };allow-transfer {none;}; root:~ # vi /etc/named.rfc1912.zoneszone "qh.com" { type slave;masters {192.168.64.37;}; file "slaves/qh.com.slave";};root:/var/named/slaves # systemctl start named.service root:/var/named/slaves # rndc reload root:/var/named/slaves # lltotal #已同步-rw-r--r-- 1 named named 269 Apr 2316:34 qh.com.slave
7测试从服务器
img
8配置com域服务器
12345678910111213141516171819202122232425262728
root:~ # yum install bindroot:~ # vi /etc/named.conf// listen-on port 53 { 127.0.0.1; };// allow-query { localhost; };allow-transfer {none;}; ------------------------------------------------root:~ # vi /etc/named.rfc1912.zoneszone "com"IN { type master; file "com.zone";};---------------------------------------------------------root:~ # cd /var/named/root:/var/named # vim com.zone$TTL 1D@ IN SOA NS1 qh.mail.com. (11D 1H 1W 3D ) NS ns1qh NS qhns1qh NS qhns2ns1 A 192.168.64.27qhns1 A 192.168.64.37#主服务器qhns2 A 192.168.64.47#从服务器root:/var/named # chgrp named com.zone root:/var/named # chmod g+w com.zone root:/var/named # systemctl start named.service root:/var/named # rndc reloadserver reload successful
9测试 (通过父域192.168.64.27测试)
img
10搭建根DNS
123456789101112131415161718192021
root:~ # yum install bindroot:~ # vi /etc/named.conf// listen-on port 53 { 127.0.0.1; };// allow-query { localhost; };zone "."IN { type master; #改为master自己做根 file "root.zone";};root:~ # cd /var/named/root:/var/named # vim root.zone$TTL 1D@ IN SOA ns1 qh.mail.com. (11D 1H 1W 3D ) NS ns1com NS comns1ns1 A 192.168.64.17comns1 A 192.168.64.27root:/var/named # chgrp named com.zone root:/var/named # chmod g+w com.zone root:/var/named # systemctl start named.service
11测试(通过主根服务器测试)
img
12配置本地dns服务器
123456789
root:~# yum install bindroot:~# vi /etc/named.conf//listen-onport53{127.0.0.1;};//allow-query{localhost;};root:/etc/sysconfig/network-scripts# vi /var/named/named.ca #改为下面配置.518400INNSa.root-servers.net.a.root-servers.net.3600000INA192.168.64.17
13清缓存
1
root:/var/named # rndc flush #清理所有dns缓存
14在本地dns修改安全配置
123
root:~# vi /etc/named.conf dnssec-enableno;dnssec-validationno;
15测试
img
一些过程中可能遇到的错误
12
root:/var/named # systemctl start named.serviceJob for named.service failed because the control process exited with error code. See "systemctl status named.service"and"journalctl -xe"for details.
一般可以通过systemctl status named.service -l 命令可以查看当前错误类型
img
1234567891011121314151617181920212223
#dig A example.com;<<>>DiG9.9.4-RedHat-9.9.4-14.el7<<>>Aexample.com;;global options:+cmd;;Got answer:;;->>HEADER<<-opcode:QUERY,status:NOERROR,id:30523...SERVFAIL:Thenameserverencounteredaproblemwhileprocessingthequery.•可使用dig+trace排错,可能是网络和防火墙导致NXDOMAIN:Thequeriednamedoesnotexistinthezone.•可能是CNAME对应的A记录不存在导致REFUSED:Thenameserverrefusedtheclient'sDNSrequestduetopolicyrestrictions.•可能是DNS策略导致•NOERROR不代表没有问题,也可以是过时的记录•查看是否为权威记录,flags:aa标记判断•被删除的记录仍能返回结果,可能是因为*记录存在•如:*.example.com.INA172.25.254.254•注意“.”的使用•避免CNAME指向CNAME记录,可能产生回环•est.example.com.INCNAMElab.example.com.•lab.example.com.INCNAMEtest.example.com.•正确配置PTR记录,许多服务依赖PTR,如sshd,MTA•正确配置轮询round-robin记录