Linux网络服务教程——DNS域名系统服务之DNS缓存服务器实验

DNS缓存服务器

上一节讲了关于DNS主从的实验,DNS的主从主要目的是为了减轻对主服务器的访问压力以及对主服务器的数据备份功能。(回顾上一节)

 

那除了主从的实验,我们还有一个DNS缓存服务器的一个实验。那这个呢,它的这个基本原理哈,是这样的,DNS呢,本来主从是可以减轻主服务器的压力,但实际上解析效率还是一样的,那我们想着对这个解析效率的提高就需要这样来做。

大家都知道某些网站的访问频率肯定会相对比较多,比如说搜索引擎的使用,效率就相对比较多一些,那这个时候呢我们最好是能够将那种搜索引擎的解析记录或解析过程放在前边,当有用户来进行这种某一个网址、比如某一个搜索引擎的这种域名的解析时就可以快速的解析。

就是我们想着实现经常被解析到的一些解析记录放在前边,并且呢,进行对应的缓存,当有用户来进行访问时,直接通过对应的缓存记录就可以将对应的解析告诉用户,而不用每次都去查询一个很庞大的数据库来进行这样的一个数据检索,要不然很浪费时间。所以说缓存DNS的功能主要是加快解析效率,提高工作效率的。

 

我们接着主从的实验来做,简单的做一下修改就行了。

 

实验作用:
加快解析速度,提高工作效率
实验软件:
dnsmasq
配置文件:
/etc/dnsmasq.conf
domain=域名 #需要解析的域名
server=ip #主 DNS 服务器 IP
cache-size=15000 #声明缓存条数
重启服务:
service dnsmasq restart
测试效果:
在测试机上填写 DNS 缓存服务器的 ip 地址

 

 

那主DNS肯定不用管,我们只需要管一下缓存DNS就可以了。

先把主服务器启动起来

service named start

把从服务器的服务停掉

service named stop 

把从服务器改成DNS缓存服务器(重命名标签)

把对应的软件安装一下

yum -y install dnsmasq

编辑配置文件

vim /etc/dnsmasq.conf

# Set the domain for dnsmasq. this is optional, but if it is set, it
# does the following things.
# 1) Allows DHCP hosts to have fully qualified domain names, as long
#     as the domain part matches this setting.
# 2) Sets the "domain" DHCP option thereby potentially setting the
#    domain of all systems configured by DHCP
# 3) Provides the domain part for "expand-hosts"
#domain=thekelleys.org.uk
domain=google.com      #要解析的域

# Set a different domain for a particular subnet
#domain=wireless.thekelleys.org.uk,192.168.2.0/24

# Same idea, but range rather then subnet
#domain=reserved.thekelleys.org.uk,192.68.3.100,192.168.3.200

# Uncomment this to enable the integrated DHCP server, you need
# to supply the range of addresses available for lease and optionally
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
                                                                                                123,17        22%
# Add other name servers here, with domain specs if they are for
# non-public domains.
#server=/localnet/192.168.0.1
server=192.168.66.10  #填主DNS服务器IP

# Example of routing PTR queries to nameservers: this will send all 
# address->name queries for 192.168.3/24 to nameserver 10.1.2.3
#server=/3.168.192.in-addr.arpa/10.1.2.3

# Add local-only domains here, queries in these domains are answered
# from /etc/hosts or DHCP only.
#local=/localnet/

# Add domains which you want to force to an IP address here.
# The example below send any host in doubleclick.net to a local
# webserver.
#address=/doubleclick.net/127.0.0.1
                                                                                            63,29          8%
# Set the cachesize here.
cache-size=150    #取消注释就可以了

# If you want to disable negative caching, uncomment this.
#no-negcache

# Normally responses which come form /etc/hosts and the DHCP lease
# file have Time-To-Live set as zero, which conventionally means
# do not cache further. If you are happy to trade lower load on the
# server for potentially stale date, you can set a time-to-live (in
# seconds) here.
#local-ttl=

# If you want dnsmasq to detect attempts by Verisign to send queries
# to unregistered .com and .net hosts to its sitefinder service and
# have dnsmasq instead return the correct NXDOMAIN response, uncomment
# this line. You can add similar lines to do the same for other
# registries which have implemented wildcard A records.
#bogus-nxdomain=64.94.110.11

                                                                                                430,4         83%

 

启动缓存服务器

service dnsmasq start

测试机测试

[root@localhost ~]# nslookup www.google.com
Server:        192.168.66.20
Address:    192.168.66.20#53

Name:    www.google.com
Address: 192.168.66.30

解析到了。

 

现在把主服务器停掉

service named stop

再拿测试机通过缓存服务器测试

[root@localhost ~]# nslookup www.google.com
Server:        192.168.66.20
Address:    192.168.66.20#53

Non-authoritative answer:  #多了一个说明,告诉你这不是一个权威的回答
Name:    www.google.com
Address: 192.168.66.30

还是能解析到,但是结果还是有所不同的。

 

除此之外还有区别吗?还有。如果说主服务器和缓存服务器都开启着,那我们现在访问一个新的域名的话,顺序是这样的:测试机比如要访问dns.google.com ,那首先访问缓存,缓存里面没有就找主服务器要,从主服务器要到,放到缓存一份,再给客户端一份,是这样一个过程。

但是如果主服务器停了,客户端访问了一个缓存上没有的,比如说访问了dns.google.com,那缓存服务器就会找主服务器要,但主服务器已经停了,它要不到,那这个时候缓存服务器上又没有,所以就访问不了。比如说现在主服务已经停掉了,来测试一下

[root@localhost ~]# nslookup dns.google.com
;; connection timed out; trying next origin
;; connection timed out; no servers could be reached

你会发现是解析不了的。为什么?因为缓存上没有,你去找缓存要,缓存去找主服务器要,主服务器不搭理它,那肯定就是解析不到任何结果。

 

我们把主服务器打开

service named start

再来通过测试机再去访问缓存

[root@localhost ~]# nslookup dns.google.com
Server:        192.168.66.20
Address:    192.168.66.20#53

Name:    dns.google.com
Address: 192.168.66.10

你看,就没有问题,就可以解析到了。

 

注意,主缓之间的工作模式是客户端找缓存服务器,缓存服务器找主服务器要,要到了则缓存上有,客户端得到答案;若是缓存向主服务器要不到,则客户端也从缓存这要不到。这就是主缓的格式。

注意,主缓和主从是有区别的,主从是为了降低主服务器上的访问压力,并且对数据进行备份,而主缓的作用是为了加快解析效率,提高解析的速度。

 

以上就是DNS缓存服务器的实验搭建。

 

posted @ 2020-02-14 16:30  hkxxf  阅读(571)  评论(0编辑  收藏  举报