[desktop] 提高上网速度

aihua 2007-02-23
   这几天用ubuntu上网特慢,发现在解析DNS时基本卡住,搜索了一下找到了一个解决办法。
   通过设置DNS缓存来提高上网速度,我自己试过了,确实是解决了我的问题。


-------------------------------------
转载地址 url: http://forum.ubuntu.org.cn/viewtopic.php?t=22361&highlight=%E4%B8%8A%E7%BD%91%E6%85%A2
-------------------------------------


论坛里面有不少关于 firefox上网慢的话题。

有的说把IPv6的协议禁用,还有的对firefox进行配置,实际使用效果都不好。

我仔细看过所谓对firefox的优化参数之后,发现它们大多只不过添加了 多线程下载网页的功能,所以实际用处不大。

不信,你可以打开终端, 同时用 w3m (文字版的互联网浏览器) 和firefox打开一个你从未访问过的网页,你会发现,其实w3m也很慢。
这就说明了,浏览慢,并不仅仅是浏览器的问题。

所有这些东西,其实只用安装一个 叫做 fasterfox 的firefox浏览器扩展插件就可以自动给你设置了。设置一些优化参数的确对加快firefox的运行,而不是浏览速度 ,有帮助。

上网慢 真正的原因,仔细观察会发现,主要在firefox 花费在解析域名 的时间上。

所以有必要设置DNS缓存。

windows下面是自动设置的,所以不用操心。

在ubuntu下面就要花费一番功夫了。

所以需要装一个 叫做 dnsmasq的软件,它能提供dns解析的功能。
当然,改造一下,也能提供dns缓存的功能。


_____________________________________
具体操作
---------------------


安装dnsmasq
命令: sudo apt-get install dnsmasq

编辑dnsmasq的配置文件
命令: sudo gedit /etc/dnsmasq.conf

找到下面这一项
#resolv-file=

用下面的一条语句替换
resolv-file=/etc/resolv.dnsmasq.conf

确保你没有更改过/etc/resolv.conf文件,如果改过,恢复原状
然后执行命令
sudo cp /etc/resolv.conf /etc/resolv.dnsmasq.conf

然后编辑resolv.conf
命令;sudo gedit /etc/resolv.conf

将其中的域名服务器全部去掉,加入以下这行
nameserver 127.0.0.1

保存,退出


执行以下命令
sudo gedit /etc/ppp/peers/dsl-provider
在 usepeerdns 前面增加 # ,也就是把这条语句覆盖掉。
以防,resolv.conf的设置被pppoe覆盖。

重启电脑。不重启,你会发现无法解析域名。所以一定要重启电脑,来达到重新启动dnsmasq的目的。
重启后, 你会发现firefox的解析速度比以前快了N个数量级。
Sam1860 2007-02-28
我在6.10上按照上面的方法做搞到系统都出问题了,然后按照下面这篇文章做才成功了http://www.debianadmin.com/local-dns-cache-for-faster-browsing-on-ubuntu-system.html

Local DNS Cache for Faster Browsing on Ubuntu System
引用

A DNS server resolves domain names into IP addresses. So when you request “yahoo.com” for example, the DNS server finds out the address for the domain, and sends your request the right way.

You can run a DNS cache on your computer. This will speed up the process of looking up domain names when browsing. The difference is about 30-60 ms. Multiply that difference by the number of websites you visit a day for an approximate estimate of the speed improvement.

The following instructions are for someone with a broadband internet connection, where the computer gets it’s local IP address using DHCP from the router in your home or office.

Install dnsmasq in Ubuntu

Dnsmasq is a lightweight, easy to configure, DNS forwarder and DHCP server. It is designed to provide DNS and optionally, DHCP, to a small network. It can serve the names of local machines which are not in the global DNS. The DHCP server integrates with the DNS server and allows machines with DHCP-allocated addresses to appear in the DNS with names configured either in each host or in a central configuration file. Dnsmasq supports static and dynamic DHCP leases and BOOTP for network booting of diskless machines.

First you need to make sure that Universe repository is enabled in your sources.list file

Install dnsmasq Using the following command

sudo apt-get install dnsmasq

uncomment the following line (remove “#” in the beginning) in the file /etc/dnsmasq.conf

listen-address=127.0.0.1

Now edit

/etc/dhcp3/dhclient.conf

and make sure the section below exactly like this, especially the line that says “prepend domain-name-servers 127.0.0.1;”

#supersede domain-name “fugue.com home.vix.com”;
prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, host-name,
netbios-name-servers, netbios-scope;

In the normal case, when you get a new dhcp lease, the dhcp3 client (tool) on your computer gets a new lease, and updates the

/etc/resolv.conf

file on your computer with the right values for the DNS servers to use (usually some machine in the network of your hosting provider). Adding the “prepend” option as we did above ensures that “127.0.0.1″ will appear on the top of the list of DNS servers. That magic number refers to your own computer. So in the future, whenever your computer needs to resolve a domain name, it will forward that request to dnsmasq (which is running at 127.0.0.1 - your computer). If the details for the domain name are already in you cache, well and good, dnsmasq will serve it up and make the process real fast. If it is not in the cache, then dnsmasq will look at the /etc/resolv.conf file and use the nameservers listed below the “127.0.0.1″. I hope that explains things.

Now open the file

/etc/resolv.conf

in your text editor. It probably looks like:

search yourisp.com
nameserver 217.54.170.023
nameserver 217.54.170.024
nameserver 217.54.170.026

The 127.0.0.1 is missing right now since you haven’t renewed your lease after you edited the /etc/dhcp3/dhclient.conf file. So, let us add that in manually this one time. After you do, your /etc/resolv.conf file will look like the following:

search yourisp.com
nameserver 127.0.0.1
nameserver 217.54.170.023
nameserver 217.54.170.024
nameserver 217.54.170.026

Now you need to restart the dnsmasq using the following command

sudo /etc/init.d/dnsmasq restart.

Now you are running a local DNS cache.

Testing Your Local DNS Cache

If you want to measure your speed improvement, type the command

dig yahoo.com

You will see something like “;; Query time: 38 msec” there.

Now type the command again, and you should see something like:”;; Query time: 2 msec”
aihua 2007-02-28
我的系统是6.06
darknight512 2007-03-02
用6.10,没感觉上网慢嘛,和在win下差不多
Sam1860 2007-03-02
不是上网慢,是解释DNS慢,我这里还经常出现server not found,设了DNS缓存后是快了。
gdzhljw 2007-06-12
很好啊!怎么能收藏起来?
gm8pleasure 2007-06-26
这个DNS缓存确实比较实用!
fsword 2007-09-16
不错,效果非常好

不过看到这句话实在忍不住想补充一下
aihua 写道
  重启电脑。不重启,你会发现无法解析域名。所以一定要重启电脑,来达到重新启动dnsmasq的目的。

linux一般都不需要重启电脑的,要重启的是dnsmasq服务,下面这样就可以了:
sudo /etc/init.d/dnsmasq restart
wenjinlan 2007-09-19
我用的是ubuntu7。04感觉还行吧!没有碰到这样的问题。
gm8pleasure 2007-10-16
在加上一个Squid本机代理,那速度。。。
Global site tag (gtag.js) - Google Analytics