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中国”

相关文章
|
15天前
|
机器学习/深度学习 人工智能 负载均衡
深度解析:Linux内核调度策略的演变与优化
【5月更文挑战第30天】 随着计算技术的不断进步,操作系统的性能调优成为了提升计算机系统效率的关键。在众多操作系统中,Linux因其开源和高度可定制性而备受青睐。本文将深入剖析Linux操作系统的内核调度策略,追溯其历史演变过程,并重点探讨近年来为适应多核处理器和实时性要求而产生的调度策略优化。通过分析比较不同的调度算法,如CFS(完全公平调度器)、实时调度类和批处理作业的调度需求,本文旨在为系统管理员和开发者提供对Linux调度机制深层次理解,同时指出未来可能的发展趋势。
|
30天前
|
Linux Shell 网络安全
LabVIEW NI Linux Real-Time深层解析
LabVIEW NI Linux Real-Time深层解析
23 0
|
6天前
|
Linux 数据库 数据库管理
Linux下的`db_checkpoint`命令:深入解析与应用
`db_checkpoint`是Linux下Berkeley DB的命令,用于触发检查点操作,保证数据库故障恢复时的一致状态。它锁定数据库、刷新内存中的写入、更新日志并解锁。在Linux中,通过命令行调用,如`db_checkpoint -h /path/to/db_home`,可配合 `-f` 强制写入,`-v` 获取详细输出。注意权限、并发性能影响及事务一致性。使用得当能提升数据库可靠性和性能。
|
8天前
|
网络协议 Linux 开发者
探索Linux下的`dig`命令:DNS查询的利器
`dig`是Linux下强大的DNS查询工具,适用于系统管理员、网络工程师和开发者。它支持查询A、MX、NS、CNAME等记录类型,以及反向DNS。高级功能包括跟踪查询过程、显示额外信息、指定查询服务器和批量查询。学习`dig`能助你更好地理解DNS工作原理和优化网络问题。
|
8天前
|
存储 安全 算法
深入解析Linux命令:cksum
`cksum`是Linux中用于计算文件CRC校验和及字节数的命令,有助于验证文件完整性。它的语法是`cksum [OPTION]... [FILE]...`,常用选项包括`-b`(按字节显示文件大小)、`-c`(检查校验和文件)等。通过示例展示了如何计算单个或多个文件的CRC,以及如何验证文件完整性。在系统管理和网络安全中,`cksum`可用于文件传输验证、备份检查和安全审计,确保文件未被篡改。
|
8天前
|
安全 Linux
Linux命令深度解析:`chgrp` - 改变文件或目录的组所有权
`chgrp`是Linux命令,用于改变文件或目录的组所有权。基本语法是`chgrp [选项] 新组 文件或目录...`。常用选项包括`-R`(递归更改)、`-c`(显示诊断信息)和`-v`(详细输出)。例如,`chgrp developers example.txt`将文件`example.txt`的组更改为`developers`。注意,需有相应权限才能执行此命令,且理解更改所有权可能影响系统安全。
|
8天前
|
Ubuntu Linux
深入解析 Linux 命令 `bzgrep`:快速搜索 Bzip2 压缩文件
`bzgrep`是Linux下用于在Bzip2压缩文件中搜索模式的工具,结合了`grep`和Bzip2的功能,允许用户无需解压即可搜索。安装`bzgrep`需通过包管理器如`apt-get`或`yum`。基本用法与`grep`类似,如`bzgrep "example" filename.txt.bz2`。可搭配`-i`, `-l`, `-n`等选项使用,并可通过`find`和`xargs`进行递归搜索。虽然对大文件可能较慢,但比完全解压更快。对于处理压缩文本数据的用户,`bzgrep`是必备工具。
|
8天前
|
Ubuntu Linux
深入解析Linux命令:bootctl1
`bootctl`是Linux系统中用于管理systemd-boot(EFI引导加载程序)的命令行工具,常用于配置UEFI硬件。要安装它,可以使用包管理器如`apt-get install systemd-boot`。基本操作包括列出引导条目、添加新条目、更新配置。在使用时要注意理解EFI引导原理,备份数据,并查阅文档以避免错误。了解`bootctl`能帮助用户自定义Linux启动过程。
|
8天前
|
Ubuntu Linux 编译器
深入解析Linux命令:autoheader
`autoheader`是Linux开发中的自动化工具,用于从`configure.ac`生成`config.h.in`模板,帮助创建平台适应性和用户配置选项。通过`autoheader`与`autoconf`配合,开发者能简化跨平台项目的构建过程,自定义配置并减少手动工作。安装`autoconf`即可获得`autoheader`,使用简单,可定制`acconfig.h`添加额外内容。适用于跨平台开发、自定义配置和自动化构建。
|
14天前
|
弹性计算 负载均衡 网络协议
LVS (Linux Virtual server)集群介绍
LVS (Linux Virtual server)集群介绍

相关产品

  • 云解析DNS