DNS解析及轮询

一、DNS排错


 NOERROR                                                                    ###查询成功
 NXDOMAIN                                                                   ###DNS服务器提示不存在这样的名称
 SERVFAIL                                                                   ###DNS服务器停机或DNSSEC响应验证失败
 REFUSED                                                                    ###DNS服务器拒绝回答

二、高速缓存DNS


虚拟机IP:172.25.254.125(服务器)

selinux iptables off

1、安装DNS

 yum install bind.x86_64 -y 
 systemctl start named                                                      ###启动服务
 cat /etc/rndc.key                                                          ###开始不存在,服务启动建立
 cat /etc/services |grep domain                                             ###查看DNS的端口

2、配置named.conf

 vim /etc/named.conf
 10 options {
 11         listen-on port 53 { any; };                                     ###开启53端口访问
 12         listen-on-v6 port 53 { ::1; };
 13         directory       "/var/named";
 14         dump-file       "/var/named/data/cache_dump.db";
 15         statistics-file "/var/named/data/named_stats.txt";
 16         memstatistics-file "/var/named/data/named_mem_stats.txt";
 17         allow-query     { any; };                                       ###允许所有人访问
 18         forwarders { 172.25.254.250; };                                 ###如果没有就访问172.25.254.250
 19         /* 

 systemctl restart named

3、测试

 虚拟机IP:172.25.254.225
 vim /etc/resolv.conf
 nameserver 172.25.254.125

 虚拟机IP:172.25.254.56
 vim /etc/resolv.conf
 nameserver 172.25.254.125

测试结果:2台分别访问dig www.baidu.com,可以发现第一次慢,第二次快

三、DNS正向解析


原理:将域名转化为IP地址

1、配置named.conf

虚拟机IP:172.25.254.125(服务器)

 vim /etc/named.conf
 10 options {
 11         listen-on port 53 { any; };                                         ###开启53端口访问
 12         listen-on-v6 port 53 { ::1; };
 13         directory       "/var/named";
 14         dump-file       "/var/named/data/cache_dump.db";
 15         statistics-file "/var/named/data/named_stats.txt";
 16         memstatistics-file "/var/named/data/named_mem_stats.txt";
 17         allow-query     { any; };                                           ###允许所有人访问
 18         /* 

2、配置named.rfc1912.zones

 vim /etc/named.rfc1912.zones
 19 zone "localhost" IN {                                                       ###y6y复制,p粘贴
 20         type master;
 21         file "named.localhost";
 22         allow-update { none; };
 23 };
 24 
 25 zone "dream.com" IN {
 26           type master;
 27           file "dream.com.zone";                                            ###访问的文件
 28           allow-update { none; };
 29 };

 cp -p /var/named/named.localhost /var/named/dream.com.zone

3、配置dream.com.zone

  vim /var/named/dream.com.zone                                                 ###结尾加点表示结束,如果没有会补(.dream.com)
  1 $TTL 1D
  2 @       IN SOA  dns.dream.com. root.dream.com. (
  3                                         0       ; serial
  4                                         1D      ; refresh
  5                                         1H      ; retry
  6                                         1W      ; expire
  7                                         3H )    ; minimum
  8         NS      dns.dream.com.                                              ###nameserver:下面指向服务器的IP
  9 dns     A       172.25.254.125
 10 www     A       172.25.254.225                                              ###把www.dream.com解析到172.25.254.225这个IP

4、测试

真机IP:172.25.254.56

 vim /etc/resolv.conf
 nameserver 172.25.254.125
 dig www.dream.com

这里写图片描述

四、DNS轮询

注意:此功能DNS自带,在DNS正向解析的条件下!!!

1、配置dream.com.zone

  vim /var/named/dream.com.zone
  1 $TTL 1D
  2 @       IN SOA  dns.dream.com. root.dream.com. (
  3                                         0       ; serial
  4                                         1D      ; refresh
  5                                         1H      ; retry
  6                                         1W      ; expire
  7                                         3H )    ; minimum
  8         NS      dns.dream.com.
  9 dns     A       172.25.254.125
 10 www     CNAME   login.dream.com.
 11 login   A       172.25.254.225
 12 login   A       172.25.254.56

 systemctl restart named

2、测试

真机IP:172.25.254.56

 dig www.dream.com

这里写图片描述

这里写图片描述

五、DNS反向解析


原理:将IP地址转化为域名
在DNS正向解析的条件下,虚拟机IP:172.25.254.125(服务器)

1、配置named.rfc1912.zones

 vim /etc/named.rfc1912.zones
 43 zone "0.in-addr.arpa" IN {
 44         type master;
 45         file "named.empty";
 46         allow-update { none; };
 47 };
 48 
 49 zone "254.25.172.in-addr.arpa" IN {
 50         type master;
 51         file "dream.com.ptr";
 52         allow-update { none; };
 53 };

 cp -p /var/named/named.loopback /var/named/dream.com.ptr

2、配置dream.com.ptr

 vim /var/named/dream.com.ptr
  1 $TTL 1D
  2 @       IN SOA  dns.dream.com. root.dream.com. (
  3                                         0       ; serial
  4                                         1D      ; refresh
  5                                         1H      ; retry
  6                                         1W      ; expire
  7                                         3H )    ; minimum
  8         NS      dns.dream.com.
  9 dns     A       172.25.254.125
 10 225     PTR     www.dream.com
 11 56      PTR     login.dream.com

 systemctl restart named

3、测试

真机IP:172.25.254.56

 dig -x 172.25.254.56                                                  ###反向解析到login.dream.com            
 dig -x 172.25.254.225                                                 ###反向解析到www.dream.com

这里写图片描述

这里写图片描述

六、DNS双向解析


运用DNS双向解析,我们可以让内外网访问的网段不同。这里我们以外网访问172.25.254网段,内网访问192.25.254网段为例。

1、配置dream.com.inter

 cp -p /var/named/dream.com.zone /var/named/dream.com.inter

 vim /var/named/dream.com.inter
  1 $TTL 1D
  2 @       IN SOA  dns.dream.com. root.dream.com. (
  3                                         0       ; serial
  4                                         1D      ; refresh
  5                                         1H      ; retry
  6                                         1W      ; expire
  7                                         3H )    ; minimum
  8         NS      dns.dream.com.
  9 dns     A       192.25.254.125
 10 www     CNAME   login.dream.com.
 11 login   A       192.25.254.225
 12 login   A       192.25.254.56

2、配置named.rfc1912.zones.inter

 cp -p /etc/named.rfc1912.zones /etc/named.rfc1912.zones.inter

 vim /etc/named.rfc1912.zones.inter 
 25 zone "dream.com" IN {
 26         type master;
 27         file "dream.com.inter";
 28         allow-update { none; };
 29 };

3、配置named.conf

 vim /etc/named.conf
 51 #zone "." IN {
 52 #       type hint;
 53 #       file "named.ca";
 54 #};
 55 #
 56 #include "/etc/named.rfc1912.zones";
 57 #include "/etc/named.root.key";
 58 view localnet {
 59         match-clients { 172.25.254.125; };                                  ###这里为了测试方便把125当成内网,其他为外网。应该写localhost 
 60         zone "." IN {
 61         type hint;
 62         file "named.ca";
 63         };
 64 include "/etc/named.rfc1912.zones.inter";
 65 };
 66 view internet {
 67         match-clients { any; };
 68         zone "." IN {
 69         type hint;
 70         file "named.ca";
 71         };
 72 include "/etc/named.rfc1912.zones";
 73 };

 systemctl restart named

4、测试

(1)在IP:172.25.254.125(服务器)中/etc/resolv.conf加入nameserver 172.25.254.125,dig www.dream.com

这里写图片描述

(2)在IP:172.25.254.225中dig www.dream.com

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wielun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值