使用Dnsmasq搭建本地dns服务器上网
2016-05-25 08:59
441 查看
导读 | 搭建一个属于自己的本地DNS服务器很有必要,利用Dnsmasq来搭建一个属于自己的本地DNS服务器,享受更干净无污染、更智能快速和没有广告干扰的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多
4、第二次再次测试,因为已经有了缓存,所以查询时间已经变成了0.
本文转载自:http://www.linuxprobe.com/dnsmasq-builds-local-dns.html
免费提供最新Linux技术教程书籍,为开源技术爱好者努力做得更多更好:http://www.linuxprobe.com/
相关文章推荐
- java中方法重载和方法重写分析
- eclipse发布cxf2 webService
- java入门教程-4.9Java Object类
- ubuntu 下使用apt 安装android studio
- hdu5694--BD String(2016百度之星Round2A/1005)
- 在CentOS 7 上安装广告服务器 Revive Adserver
- GEEK编程练习— —四数求和
- In-Memory Natively Compiled vs Interpreted Stored Procedures Performance Comparison in SQL Server 20
- Swift 必备开发库 (高级篇)
- 2016年5月24日上午(妙味课堂js预热课程-2笔记)
- java入门教程-4.8Java final关键字:阻止继承和多态
- Extjs MVC开发模式详解
- QPBOC交易流程详解--POS与卡片的数据交互进行分析
- html5 websocket
- 对比Java中的Comparable排序接口和Comparator比较器接口
- poj 2755 神奇的口袋(dp)
- Android应用开发项目结构分析
- 电子钱包、电子现金与qPBOC
- java入门教程-4.7Java static关键字以及Java静态变量和静态方法
- 金融系统中PBOC/EMV的TLV的算法实现(含C++/C#)