使用Dnsmasq搭建本地dns服务器上网

想要了解更多,加QQ群72132378


导读搭建一个属于自己的本地DNS服务器很有必要,利用Dnsmasq来搭建一个属于自己的本地DNS服务器,享受更干净无污染、更智能快速和没有广告干扰的DNS解析服务。

small-dns

一、Dnsmasq安装
安装并启动Dnsmasq
yum install -y dnsmasq
service dnsmasq start 
二、Dnsmasq配置
1、Dnsmasq的配置文件路径为:/etc/dnsmasq.conf
# ll -d /etc/dnsmasq.conf 
-rw-r--r-- 1 root root 21237 Feb 23 00:17 /etc/dnsmasq.conf
2、编辑/etc/dnsmasq.conf
resolv-file=/etc/resolv.dnsmasq.conf    //dnsmasq 会从这个文件中寻找上游dns服务器
strict-order             //去掉前面的#
addn-hosts=/etc/dnsmasq.hosts         //在这个目里面添加记录
listen-address=127.0.0.1,192.168.1.123     //监听地址
3、修改/etc/resolv.conf
echo 'nameserver 127.0.0.1' > /etc/resolv.conf
4、创建resolv.dnsmasq.conf文件并添加上游dns服务器的地址
touch /etc/resolv.dnsmasq.conf
echo 'nameserver 119.29.29.29' > /etc/resolv.dnsmasq.conf
5、创建dnsmasq.hosts文件
cp /etc/hosts /etc/dnsmasq.hosts
echo 'addn-hosts=/etc/dnsmasq.hosts' >> /etc/dnsmasq.conf

提示:resolv.dnsmasq.conf中设置的是真正的Nameserver,可以用电信、联通等公共的DNS。

三、Dnsmasq启动
1、设置Dnsmasq开机启动并启动Dnsmasq服务:
chkconfig dnsmasq on
/etc/init.d/dnsmasq restart
2、netstat -tunlp|grep 53 查看Dnsmasq是否正常启动:
# netstat -tlunp|grep 53
tcp        0      0 0.0.0.0:53                  0.0.0.0:*                   LISTEN      2491/dnsmasq        
tcp        0      0 :::53                       :::*                        LISTEN      2491/dnsmasq        
udp        0      0 0.0.0.0:53                  0.0.0.0:*                               2491/dnsmasq        
udp        0      0 :::53                       :::*                                    2491/dnsmasq        
3、dig www.freehao123.com,第一次是没有缓存,所以时间是200多

Dnsmasq_01

4、第二次再次测试,因为已经有了缓存,所以查询时间已经变成了0.

Dnsmasq_2


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值