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 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?

原文发布时间为:2011-03-28


本文来自云栖社区合作伙伴“Linux中国”

相关文章
|
6天前
|
安全 Linux iOS开发
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
66 0
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
|
2月前
|
缓存 监控 Linux
Linux系统清理缓存(buff/cache)的有效方法。
总结而言,在大多数情形下你不必担心Linux中buffer与cache占用过多内存在影响到其他程序运行;因为当程序请求更多内存在没有足够可用资源时,Linux会自行调整其占有量。只有当你明确知道当前环境与需求并希望立即回收这部分资源给即将运行重负载任务之前才考虑上述方法去主动干预。
736 10
|
7月前
|
监控 Shell Linux
Android调试终极指南:ADB安装+多设备连接+ANR日志抓取全流程解析,覆盖环境变量配置/多设备调试/ANR日志分析全流程,附Win/Mac/Linux三平台解决方案
ADB(Android Debug Bridge)是安卓开发中的重要工具,用于连接电脑与安卓设备,实现文件传输、应用管理、日志抓取等功能。本文介绍了 ADB 的基本概念、安装配置及常用命令。包括:1) 基本命令如 `adb version` 和 `adb devices`;2) 权限操作如 `adb root` 和 `adb shell`;3) APK 操作如安装、卸载应用;4) 文件传输如 `adb push` 和 `adb pull`;5) 日志记录如 `adb logcat`;6) 系统信息获取如屏幕截图和录屏。通过这些功能,用户可高效调试和管理安卓设备。
|
9月前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
316 11
|
网络协议 Linux Docker
在Linux中,如何指定dns服务器,来解析某个域名?
在Linux中,如何指定dns服务器,来解析某个域名?
|
9月前
|
存储 运维 安全
深入解析操作系统控制台:阿里云Alibaba Cloud Linux(Alinux)的运维利器
本文将详细介绍阿里云的Alibaba Cloud Linux操作系统控制台的功能和优势。
278 6
|
11月前
|
缓存 并行计算 Linux
深入解析Linux操作系统的内核优化策略
本文旨在探讨Linux操作系统内核的优化策略,包括内核参数调整、内存管理、CPU调度以及文件系统性能提升等方面。通过对这些关键领域的分析,我们可以理解如何有效地提高Linux系统的性能和稳定性,从而为用户提供更加流畅和高效的计算体验。
414 24
|
11月前
|
算法 Linux 定位技术
Linux内核中的进程调度算法解析####
【10月更文挑战第29天】 本文深入剖析了Linux操作系统的心脏——内核中至关重要的组成部分之一,即进程调度机制。不同于传统的摘要概述,我们将通过一段引人入胜的故事线来揭开进程调度算法的神秘面纱,展现其背后的精妙设计与复杂逻辑,让读者仿佛跟随一位虚拟的“进程侦探”,一步步探索Linux如何高效、公平地管理众多进程,确保系统资源的最优分配与利用。 ####
194 4
|
11月前
|
缓存 负载均衡 算法
Linux内核中的进程调度算法解析####
本文深入探讨了Linux操作系统核心组件之一——进程调度器,着重分析了其采用的CFS(完全公平调度器)算法。不同于传统摘要对研究背景、方法、结果和结论的概述,本文摘要将直接揭示CFS算法的核心优势及其在现代多核处理器环境下如何实现高效、公平的资源分配,同时简要提及该算法如何优化系统响应时间和吞吐量,为读者快速构建对Linux进程调度机制的认知框架。 ####
|
12月前
|
网络协议 定位技术 Windows
Windows Server 2019 DNS服务器搭建
Windows Server 2019 DNS服务器搭建
412 1

热门文章

最新文章

相关产品

  • 云解析DNS