#sudo apt-get install dnsmasq
#sudo gedit /etc/dnsmasq.conf
按ctrl+F找到listen-address修改为如下:
listen-address=127.0.0.1
保存退出.
然后
#sudo gedit /etc/resolv.conf
在最前面添加一行
nameserver 127.0.0.1
ubuntu在重启后会自动修改resolv.conf ,为了防止自动修改该文件,做以下修改:
sudo gedit /etc/dhcp/dhclient.conf
找到#prepend domain-name-servers 127.0.0.1;
去掉前面的#号,也就是将它改为:
prepend domain-name-servers 127.0.0.1;
然后重启系统.
赶紧试用测试,在ubuntu firefox和ubuntu chrome中网速都得到了质的飞跃,可以说网速和windows下没有区别了。
了却了一块心病。
2011.10.20又碰到了一个奇怪的现象,当变换网络环境重新启动后,/etc/resolv.conf会被清空,所有的nameserver行都会被删除,导致无法找到DNS服务器无法上网。经分析发现/etc/dhcp/dhclient.conf中prepend domain-name-servers 127.0.0.1前面的#号不能去掉,否则就会导致这个现象发生。唉,为什么上个网这么难。
分析:
在Windows下是默认开启了DNS缓存的,因此所有解析过的域名,短时间内不可能再连接远程DNS服务器进行查询,而是直接从本地的DNS缓存 中查询,理论上讲,解析DNS的时间近似于0。而Ubuntu并没有默认开启类似的功能。解决Ubuntu上网慢的思路是在本机搭建一个DNS代理服务器,缓存DNS。
dnsmasq is a lightweight DNS, TFTP and DHCP server. It is intended toprovide coupled DNS and DHCP service to a LAN.
Dnsmasq accepts DNS queries and either answers them from a small,
local, cache or forwards them to a real, recursive, DNS server. It
loads the contents of /etc/hosts so that local hostnames which do not
appear in the global DNS can be resolved and also answers DNS queries
for DHCP configured hosts.
The dnsmasq DHCP server supports static address assignments and multi‐
ple networks. It automatically sends a sensible default set of DHCP
options, and can be configured to send any desired set of DHCP options,
including vendor-encapsulated options. It includes a secure, read-only,
TFTP server to allow net/PXE boot of DHCP hosts and also supports
BOOTP.
Dnsmasq supports IPv6 for DNS and TFTP, but not DHCP.
参考: Local DNS Cache for Faster Browsing on Ubuntu System