Linux中通过缓存DNS的解析来提高上网的响应速度!


这几天好不容易细心了一下,发现在用Firefox浏览网页的时候,一开始总会看到左下角有一行提示:

     “正在解析主机 xxx ...”   

看上去是等待DNS服务器对域名的解析,闲来无事,
于是 决定做个DNS Cache来提高上网速度!

找了找,发现有一个软件符合要求:


[xport@ubuntu ~] $ apt-cache search "dns" | fgrep "cach"
dnsmasq - A small caching DNS proxy and DHCP server



去翻翻资料,设定的步骤如下:

1. 安装dnsmasq:


# 安装dnsmasq的软件包

[xport@ubuntu ~] $ sudo apt-get install "dnsmasq"


2.设定dnsmasq接管本机的DNS解析请求:

# 修改dnsmasq的配置文件

[xport@ubuntu ~] $ sudo gedit /etc/dnsmasq.conf

# 找到下面的内容,并进行修改
# If you want dnsmasq to listen for DHCP and DNS requests only on
# specified interfaces (and the loopback) give the name of the
# interface (eg eth0) here.
# Repeat the line for more than one interface.
# interface=
# Or you can specify which interface _not_ to listen on
# except-interface=
# Or which to listen on by address (remember to include 127.0.0.1 if
# you use this.)
listen-address=127.0.0.1  # 把这一行前面的注释去掉


3.修改dhclient的配置:

# 修改dnsmasq的配置文件

[xport@ubuntu ~] $ sudo gedit /etc/dhcp3/dhclient.conf

# 找到下面的内容,并进行修改
prepend domain-name-servers 127.0.0.1;
# 把这一行前面的注释去掉
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, host-name,
        netbios-name-servers, netbios-scope;


4.修改resolv.conf的配置:

[xport@ubuntu ~] $ sudo gedit /etc/resolv.conf

# 注意:我的resolv.conf文件的内容不会因为ADSL拨号而被改写
# 因为dnsmasq会接管本机的DNS解析请求,所以把127.0.0.1的地址放在最前面
nameserver 127.0.0.1
nameserver xxx.xxx.xxx.xxx
nameserver xxx.xxx.xxx.xxx
search lan


5. 重新开启dnsmasq的服务:

[xport@ubuntu ~] $ sudo /etc/init.d/dnsmasq restart


6. 看看DNS的解析需要的时间,前后2次的数据对比:

[xport@ubuntu ~] $ dig baidu.com #首次执行
... 省略输出信息若干 ...
;; Query time: 8 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Feb 19 20:43:32 2007
;; MSG SIZE  rcvd: 229
 

[xport@ubuntu ~] $ dig baidu.com #再次运行
... 省略输出信息若干 ...
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Feb 19 20:45:27 2007
;; MSG SIZE  rcvd: 59


好了,打完收工~~~!
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值