---
title: "用dnsmasq建立dns缓存服务器"
author: "lingzantia"
date: "2009-03-13T08:54:53Z"
tags: ["Google", "Ubuntu", "vim", "电信", "百度"]
slug: "dnsmasq-dns"
draft: false
lastmod: "2009-03-13T08:54:53Z"
id: 348398
url: "https://gchuyun.iteye.com/blog/348398"
---

近几天很烦，经常开个网页突然转到http://autosearch.gd.vnet.cn/，我恨死电信拉。
google一下，找到了这个。最后发现还是je上面的文章，看来je人才何其多也。题外话，我这边google经常打不开，要用ip就可以访问，但百度一直很正常，莫非........电信.......百度.......


查看原文:http://ubuntu.group.iteye.com/group/topic/644

安装dnsmasq
命令: sudo apt-get install dnsmasq

编辑dnsmasq的配置文件
命令: sudo vim /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 vim /etc/resolv.conf

将其中的域名服务器全部去掉，加入以下这行
nameserver 127.0.0.1

保存，退出

执行以下命令
sudo gedit /etc/ppp/peers/dsl-provider

在 usepeerdns 前面增加 # ，也就是把这条语句覆盖掉。
以防，resolv.conf的设置被pppoe覆盖(因为采用adsl拨号的用户默认是从服务器更新dns服务器地址的,取消这个语句就意味着不会每次开机拨号都改变resolv.conf文件的设置。

一定要重启电脑，来达到重新启动dnsmasq的目的。 你会发现firefox的解析速度比以前快了N个数量级。
(不重启也可以,要重新启动服务, 命令: sudo /etc/init.d/dnsmasq restart )

同时,你也可以把dns地址更改为opendns的设置,这样在速度,智能性,防钓鱼站点各个方面都有所提高.

opendns的地址是(修改/etc/resolve.dnsmasq.conf文件):
nameserver 208.67.222.222
nameserver 208.67.220.220