解决ubuntu 上网慢

#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 to
       provide 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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解决Ubuntu网速的方法有多种。首先,可以通过检查网络硬件的详细信息来确定网络连接的情况,可以使用以下命令:sudo lshw -numeric -class network、sudo ip addr show、sudo ip route show、sudo traceroute forum.ubuntu.org.cn 。 其次,如果网速仍然很,尤其是网页加载速度缓,可能是DNS的问题。可以通过修改配置将本地设置为一个DNS解析服务器来解决这个问题 。具体操作如下: 1. 安装dnsmasq,用于做DNS缓存:sudo apt-get install dnsmasq 。 2. 编辑dnsmasq的配置文件:sudo vi /etc/dnsmasq.conf,在文件中找到"resolv-file=/etc/resolv.dnsmasq.conf"这一行,并修改为该行。 3. 确保/etc/resolv.conf文件中的DNS信息正确,然后执行sudo cp /etc/resolv.conf /etc/resolv.dnsmasq.conf。 4. 将/etc/resolv.conf文件中的DNS改为127.0.0.1:nameserver 127.0.0.1。 5. 如果使用adsl上网,需要修改/etc/ppp/peers/dsl-provider文件,注释掉"usepeerdns"这一行,以免它覆盖/etc/resolv.conf文件的内容。 6. 重启dnsmasq服务:sudo /etc/init.d/dnsmasq restart。 另外,如果遇到traceroute指令报错,请先安装traceroute:sudo apt-get install traceroute 。如果显示软件包被引用...的错误,请修改apt源,使用国内源的下载速度会更快。 综上所述,以上是解决Ubuntu网速的一些常用方法。希望对您有帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值