dig -t A +trace www.baidu.com ; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7 <<>> -t A +trace www.baidu.com ;; global options: +cmd . 457478 IN NS a.root-servers.net. # 首先找到跟域 com. 172800 IN NS a.gtld-servers.net. # 再找.com baidu.com. 172800 IN NS dns.baidu.com. # 最后找到dns ww.baidu.com. 1200 IN CNAME www.a.shifen.com. # 找到最后的域名 ;; Received 239 bytes from 220.181.37.10#53(ns3.baidu.com) in 13 ms # 解析的ip
1 2 3 4 5 6 7 8 9 10 11 12 13 14
dig命令介绍: dig [-t RR_TYPE] name [@SERVER] [query options]
用于测试dns系统,因此其不会查询hosts文件;
查询选项: +[no]trace:跟踪解析过程; +[no]recurse:进行递归解析; 注意:反向解析测试 dig -x IP 模拟完全区域传送: dig -t axfr DOMAIN [@server] dig +trace -t A www.baidu.com dig -x61.135.169.121
配置正向解析
1 2 3 4 5 6
vim /etc/named.rfc1912.zones # 配置文件最后面添加 zone "wlm.com" IN { type master; # {master|slave|hint|forward}; file "wlm.com.zone"; };
建立区域数据文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14
vim /var/named/wlm.com.zone #这里定义的文件要跟上一步在配置里写的文件一致 $TTL3600# 设置客户端缓存时间 $ORIGIN boss.com. # 定义当前区域的名字,下面的@就是替代这个值 @ IN SOA ns1.boss.com dnsadmin.boss.com. ( # Start Of Authority,起始授权记录;一个区域解析库有且只能有一个SOA记录,而且必须放在第一条;ns1.boss.com,该域的主域名服务器; dnsadmin.boss.com, 管理员邮箱; 2022070701 ;serial# 序列号:serial 1H ;refresh# 刷新时间间隔:refresh 10M ;retry# 重试时间间隔:retry, 3D ;expire# 过期时长:expire 1D ;negative answer ttl # negative answer ttl:否定答案的缓存时长 ) IN NS DNS # 域名服务记录;一个区域解析库可以有多个NS记录;其中一个为主的 ns1 IN A 10.0.100.17#地址记录 www IN A 10.0.100.17 zx IN CNAME www
vim /var/named/10.10.10.zone $TTL3600 $ORIGIN10.10.10.in-addr.arpa. @ IN SOA ns1.wlm.com. nsadmin.wlm.com. ( 2014100801 1H 10M 3D 12H ) IN NS ns1.wlm.com. 3 IN PTR ns1.wlm.com. 100 IN PTR mx1.wlm.com. 200 IN PTR mx2.wlm.com. 4 IN PTR www.wlm.com.
options { listen-on port 53 { 127.0.0.1; 10.10.10.10; }; listen-on-v6 port 53 { ::1; }; 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; }; allow-transfer { none; }; /* - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion. - If you are building a RECURSIVE (caching) DNS server, you need to enable recursion. - If your recursive DNS server has a public IP address, you MUST enable access control to limit queries to your legitimate users. Failing to do so will cause your server to become part of large scale DNS amplification attacks. Implementing BCP38 within your network would greatly reduce such attack surface */ recursion yes; dnssec-enableno; dnssec-validation no;
[root@ns1 named]# named-checkzone wlm.com /var/named/wlm.com.zone zone wlm.com/IN: loaded serial 2014100101 OK [root@ns1 named]# rndc reload server reload successful
在slave DNS上定义区域
1 2 3 4 5 6
[root@ns2 ~]# vim /etc/named.rfc1912.zones zone "wlm.com"IN { typeslave; #slave标记为从服务器 file "slaves/wlm.com.zone"; #代办区域文件在/var/named/slaves目录下,特定的 masters { 10.10.10.3; }; #填写主域名服务器IP };
重载配置
当主域名服务器里添加了新记录,只需要主域名服务器重载配置,从域名服务器自动同步。
1 2
rndc reload systemctl reload named.service
(1)在/var/named/slaves目录下自动同步wlm.com.zone文件
1 2 3 4
[root@ns2 slaves]# pwd /var/named/slaves [root@ns2 slaves]# ls wlm.com.zone
vim /etc/named.conf options { listen-on port 53 { 127.0.0.1; 10.10.10.11; }; # 监听本机的IP端口 listen-on-v6 port 53 { ::1; }; 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 { localhost; }; # 允许为其他主机解析 allow-transfer { none; }; # 从服务器不需要传送 forward first; # 本机不能解析的转发给10.10.10.3做解析 forwarders { 10.10.10.3; }; # 被转发的服务器IP /* - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion. - If you are building a RECURSIVE (caching) DNS server, you need to enable recursion. - If your recursive DNS server has a public IP address, you MUST enable access control to limit queries to your legitimate users. Failing to do so will cause your server to become part of large scale DNS amplification attacks. Implementing BCP38 within your network would greatly reduce such attack surface */ recursion yes; dnssec-enableno; #关闭 dnssec-validation no; #关闭
语法检查然后重启bind
1
[root@wlm ~]# systemctl restart named.service
验证:
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@wlm ~]# ping www.baidu.com PING www.a.shifen.com (220.181.112.244) 56(84) bytes of data. 64 bytes from 220.181.112.244: icmp_seq=1 ttl=128 time=6.67 ms p64 bytes from 220.181.112.244: icmp_seq=2 ttl=128 time=6.60 ms ^C --- www.a.shifen.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1005ms rtt min/avg/max/mdev = 6.608/6.640/6.672/0.032 ms [root@wlm ~]# ping www.wlm.com PING www.wlm.com (10.10.10.4) 56(84) bytes of data. ^C --- www.wlm.com ping statistics --- 2 packets transmitted, 0 received, 100% packet loss, time 1001ms