1、使用yum install dnsmasq -y 安装dns(含dns server和dns代理功能)

2、查询dnsmasq已经安装成功

[root@localhost ~]# rpm -q dnsmasq

dnsmasq-2.48-18.el6_9.x86_64

[root@localhost ~]#

3、配置/etc/dnsmasq.conf文件

对于/etc/dnsmasq.conf文件的行太多的话,我们只需要添加我们需要的行,先把所有行都注释掉,然后echo追加进去我们所需要的行。

  3.1、修改/etc/dnsmasq.conf的快速方法:在每行的头添加字符,比如"#",注释掉文件的所有行,命令如下:
sed -i 's/^/#&/g' /etc/dnsmasq.conf    //注释掉/etc/dnsmasq.conf文件中的所有的行
cat /etc/dnsmasq.conf |grep -v "#"  //查看注释是否OK

  3.2、然后把需要的行echo追加进去

echo resolv-file=/etc/resolv.dnsmasq.conf >>/etc/dnsmasq.conf    #此/etc/resolv.dnsmasq.conf文件还需后续编辑
echo strict-order >>/etc/dnsmasq.conf
echo interface=eth0  >>/etc/dnsmasq.conf               #对特定接口提供dns服务
echo addn-hosts=/etc/dnsmasq.hosts >>/etc/dnsmasq.conf  #此/etc/dnsmasq.hosts文件还需后续编辑

[root@localhost ~]# cat /etc/dnsmasq.conf |grep -v "#"            //查看echo是否追加ok
resolv-file=/etc/resolv.dnsmasq.conf
strict-order
interface=eth0  #对特定接口提供dns服务
addn-hosts=/etc/dnsmasq.hosts
[root@localhost ~]#

////////sed -i 's/^#//' 123.txt      //删除文件的行首字符#  注意 要加-i才能修改文件生效

////////sed -i 's/^/#&/g' 123.txt    //每行添加行首字符# 注意 要加-i才能修改文件生效

4、编辑配置文件

  4.1编辑/etc/resolv.dnsmasq.conf配置文件

cp /etc/resolv.conf /etc/resolv.dnsmasq.conf
[root@localhost ~]# vim /etc/resolv.dnsmasq.conf
nameserver 8.8.8.8 
[root@localhost ~]#

  4.2编辑 /etc/dnsmasq.hosts配置文件

cp /etc/hosts /etc/dnsmasq.hosts               
[root@localhost ~]# vim /etc/dnsmasq.hosts
127.0.0.1  localhost.localdomain localhost
::1  localhost6.localdomain6 localhost6
135.251.214.2 RMS.chinamobile.com *.chinamobile.com   #劫持域名映射到135.251.214.2

5、service dnsmasq restart  启动服务

[root@Apache zfp]# service dnsmasq start
Starting dnsmasq:                                          [确定]
[root@Apache zfp]#

[root@Apache zfp]# service dnsmasq status
dnsmasq (pid  1139) 正在运行...
[root@Apache zfp]#

6、查看53端口监听状态

[root@localhost ~]# netstat -tunlp |grep 53
tcp        0      0 0.0.0.0:53                  0.0.0.0:*                   LISTEN      2465/dnsmasq       
tcp        0      0 :::53                       :::*                        LISTEN      2465/dnsmasq       
udp        0      0 0.0.0.0:53                  0.0.0.0:*                               2465/dnsmasq       
udp        0      0 :::53                       :::*                                    2465/dnsmasq       
[root@localhost ~]#

7、设置随系统启动dnsmasq服务

[root@localhost ~]#chkconfig dnsmasq on   //随linux系统启动dnsmasq服务

[root@localhost ~]# chkconfig --list |grep dnsmasq    //查看是否设置成功
dnsmasq         0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@localhost ~]#

--------End Of Text-------

最新文章

  1. struts-validate.xml配置详解demo
  2. js获取URL中的参数
  3. 高性能网络编程2----TCP消息的发送
  4. hibernate错误提示
  5. 在VMware中为Linux系统安装VM-Tools的详解教程
  6. sql语句批量处理Batch
  7. 黑马程序员_static\访问权限\单例模式 大汇总
  8. Codeforces Round #366 (Div. 2) C. Thor (模拟)
  9. 用户体验 | 寻找成套的 App SDK 服务
  10. Django基础(路由、视图、模板)
  11. ionic2 rc2 添加版本更新自动升级功能
  12. Windows7环境下Excel2010中图片超链接默认打开程序修改
  13. DES加密算法—实现(C语言)
  14. .Net环境下调用ProtoBuf
  15. Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第七集之SSH远程连接——克隆与更改配置】
  16. stm8s 引脚电平异常
  17. openwrt为何需要refresh新增的补丁?
  18. JS中的phototype详解
  19. geoserver源码学习与扩展——restAPI访问
  20. codeforces 814D An overnight dance in discotheque

热门文章

  1. DotNetCore跨平台~聊聊中间件
  2. 机器学习之决策树二-C4.5原理与代码实现
  3. 并发系列(6)之 ThreadPoolExecutor 详解
  4. Springboot 系列(九)使用 Spring JDBC 和 Druid 数据源监控
  5. java爬虫系列第一讲-爬虫入门
  6. 《全栈营销之如何制作个人博客》之一:用什么开发语言和CMS系统
  7. Ajax常见面试题
  8. zList一个块状链表算法可以申请和释放同种对象指针,对于大数据量比直接new少需要差不多一半内存
  9. C#开发命名规范总结整理
  10. K3实现按虚拟件/组件发料