找回密码
 骑士注册

QQ登录

微博登录

搜索
❏ 站外平台:

Linux中国开源社区 技术 查看内容

Speed up your Internet browsing on Linux with a DNS Cache server

2011-03-28 14:44    评论: 7    

Most Linux distributions, unlike OpenSuSE, OS X and Windows, do not have a DNS Cache service installed by default.Your computer will need to lookup a website’s IP address every time you visit it. The lookup request is passed on to the DNS server(s) specified in the /etc/resolv.conf file. It will take the server a few ms (milliseconds) at best to respond. It can take a ‘long’ time if your using a slow Internet connection (or a wireless LAN).

Caching DNS acts just like a regular DNS, from the users point of view. The service is configured to respond to lookup requests and return IP addresses. If the Caching DNS does not know the answer to the request, he will simply forward the request to the correct server and then forward the reply to you once it has been received.

So what’s the difference?

An Caching DNS holds a small database of recent requests, or so to speak. He will keep each entry in his database for a specified amount of time  (more about TTL). If the Caching DNS receives a requests for a entry currently in his database, he will respond to it instantly without contacting any other servers. If the Caching DNS is on your local computer, this will occur in 0 milliseconds.
You can check the responce time of your DNS server by running the following command:

dig google.com | grep “Query time”

Let me demonstrate this by running the command two times on two different targets and explain the output.

petur@petur-desktop:/etc$ dig google.com|grep “Query time”
;; Query time: 49 msec
petur@petur-desktop:/etc$ dig google.com|grep “Query time”
;; Query time: 51 msec

Look at the above output. 49 msec (milli seconds) and 51 msec. The small difference between the lookup time for the two requests indicates that the DNS server I’m using has the answer to the request in the cache. Google.com is after all a very popular destination and someone on my campus has probably visited it recently.

What about a site nobody on my campus is likely to visit? I’ll go for australian.jp

petur@petur-desktop:/etc$ dig australian.jp|grep “Query time”
;; Query time: 610 msec
petur@petur-desktop:/etc$ dig australian.jp|grep “Query time”
;; Query time: 46 msec

The first request took 610 msec, that’s because the DNS server I’m using didn’t know the answer to my request and had to contact the DNS in charge of australian.jp (which I guess is located somewhere in Japan).

Now, the second request took only 46 msec, that’s because the DNS I’m using has cached the request and does not have to contact the _Japanese_ server again any time too soon.

When the Caching DNS receives a lookup request, he will first check to see if he has the answer cached, if not he will contact the server responsible for the domain in question.

I would like to shave those 50 msec, by average, off each site I visit on the web.

I’ll show you how this can be done on Ubuntu Linux.

Begin by installing dnsmasq either from “Applications->Ubuntu Software Center” or by using the command sudo apt-get install dnsmasq from the console.

Next you’ll need the change the order of your DNS servers, do this by going to “System->Preferences->Network Connections”
Select the name of the connection you are using and click Edit…

Goto IPv4 Settings

If you have “Method: Manual”, put “127.0.0.1,” (without the quotation marks) in front of whatever it says in your “DNS servers:” field.

If you have “Method: Automatic(DHCP)” -> Change to “Automatic (DHCP) address only” and put “127.0.0.1,8.8.8.8″ in the “DNS servers:” field.

8.8.8.8 is Googles DNS server, you might want to replace this with the one provided by your ISP (Internet Service Provider).
Reboot the network-manager service by executing the command sudo service network-manager restart from the command line.

You now have a DNS Caching service running on your computer.
Let me demonstrate the benefit:

petur@petur-desktop:/etc$ dig australian.jp|grep “Query time”
;; Query time: 610 msec
petur@petur-desktop:/etc$ dig australian.jp|grep “Query time”
;; Query time: 0 msec


Other Linux distrobutions:
1. Install dnsmasq
2. Put “nameserver 127.0.0.1″ at the top of your /etc/resolv.conf file
3. You might have to bring your interface down\up using ifconfig or ifdown\ifup

Questions or comments?

 

本文内容由 bonaba 提供
 已同步至 DeadFire的微博

最新评论

我也要发表评论

finalbug 2011-03-28 13:35 回复
好像是有用的东西,mark一下,有空试试~
九喜 2011-03-28 14:40 回复
看起来实在有难度……
懒刺猬 2011-03-28 14:47 回复
目前看不懂
windnestlinux 2011-03-28 15:04 回复
好东西啊!!不错不错,马上用fedora试下
绿色圣光 2011-03-28 15:20 回复
openSUSE默认安装了?没感觉比其他系统里快啊……
daly 2011-03-28 18:04 回复
这是神马?
bonaba 2011-03-30 11:22 回复
回复 绿色圣光 的帖子

ubuntu里dig一下,差距确实挺大,有比较才容易看出效果来啊

收藏

返回顶部

分享到微信

打开微信,点击顶部的“╋”,
使用“扫一扫”将网页分享至微信。