5fc683af4344c583.jpg_fo742.jpg

1.写在前面

Ubuntu打开网页缓慢一直是一个比较严重的问题,和DNS的解析有着直接的关系,之前也写过一个相关的文章:为何我的Ubuntu浏览网页这么卡?替换ubuntu的dns不解释!,但后来发现问题远远不止于这一个。
2.ubuntu的诟病

ubuntu太纯真了,没有做假……windows在这个问题上做了缓存机制,即解析之后会把ip保存到本地做缓存,下次使用的时候就不用继续解析了,而是从缓存里面找。在ubuntu上用firefox或者google chrome访问网页时,经常会看见 正在连接:www.example.com,正在解析:www.example.com之类的东西,这就是问题所在了。
3.解决思路

何必如此天真,效率最高才是最重要的。模仿windows的优化机制,做本地缓存,映射,访问url时先映射本地缓存,找不到的情况下再使用其他DNS服务器。
4.所需工具及相关描述

PDNSD

PDNSD(8) System Administration Commands PDNSD(8)

NAME
pdnsd – dns proxy daemon

SYNOPSIS
pdnsd [-h] [-V] [-s] [-d] [-g] [-t] [-p file] [-vn] [-mxx] [-c file]
[-4] [-6] [-a]

   This man page is an extract of the documentation of  pdnsd.   For  com‐
   plete,  current  documentation, refer to the HTML (or plain text) docu‐
   mentation (which you can find in the doc/ subdirectory of the source or
   in  a standard documentation directory, typically /usr/share/doc/pdnsd/
   if you are using a binary package).

DESCRIPTION
pdnsd is a IPv6 capable proxy domain name server (DNS) which saves the
contents of its DNS cache to the disk on exit.

OPTIONS
-4 enables IPv4 support. IPv6 support is automatically dis‐
abled (should it be available). On by default.

5.详细解决步骤

1)安装pdnsd

sudo apt-get install pdnsd

2)配置pdnsd

sudo gedit /etc/pdnsd.conf

3)修改文件,注释在该文件的注释里面有

server {
label=”resolvconf”;

}

server {
label=”resolvconf”;
ip=223.5.5.5;
ip=223.6.6.6;
timeout=30;
interval=30;
uptest=ping;
ping_timeout=50;
purge_cache=off;

}

4)修改START_DAEMON为yes

sudo gedit /etc/default/pdnsd

5)设定本地DNS

sudo gedit /etc/resolv.conf

在最前面加入nameserver 127.0.0.1

6)DHCP服务配置

sudo gedit /etc/dhcp/dhclient.conf

去掉#prepend domain-name-servers 127.0.0.1;前面的#

7)启动PDNSD

sudo /etc/init.d/pdnsd start

8)测试效果

dig www.baidu.com | grep time

结果展示:

rccoder@rccoder-Lenovo-IdeaPad-Y400:~dig baidu.com | grep time
;; Query time: 445 msec
rccoder@rccoder-Lenovo-IdeaPad-Y400:~
dig baidu.com | grep time
;; Query time: 0 msec
rccoder@rccoder-Lenovo-IdeaPad-Y400:~dig baidu.com | grep time
;; Query time: 0 msec
rccoder@rccoder-Lenovo-IdeaPad-Y400:~
dig baidu.com | grep time
;; Query time: 0 msec

转自:www.rccoder.net|若兮为尘

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code