Skip to content Skip to main navigation Skip to footer

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

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 | 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|grep “Query time” ;; Query time: 49 msec petur@petur-desktop:/etc$ dig|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. 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 petur@petur-desktop:/etc$ dig|grep “Query time” ;; Query time: 610 msec petur@petur-desktop:/etc$ dig|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 (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 “,” (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 “,″ in the “DNS servers:” field. 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|grep “Query time” ;; Query time: 610 msec petur@petur-desktop:/etc$ dig|grep “Query time” ;; Query time: 0 msec Other Linux distrobutions: 1. Install dnsmasq 2. Put “nameserver″ 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的微博

There are no comments yet

Leave a comment

Your email address will not be published.