yum安装
1 |
yum install dnsmasql -y |
1.查看主配置文件
1 |
grep -v '^#' /etc/dnsmasq.conf | grep -v '^$' |
2.主配置文件
1 |
/etc/dnsmasq.conf |
3.dnsmasq内部解析所需要的ip和域名,也就是用户自定义的域名和ip的对关系编写
1 |
/etc/dnsmasq.hosts #需要手动创建 |
4.dnsmasq的上游DNS服务器地址
1 |
/etc/resolv.dnsmasq.conf #需要手动创建 |
5.修改dnsmaq.conf.添加如下参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
resolv-file=/etc/resolv.dnsmasq.conf #指定上游DNS服务器文件地址 address=/go.com/192.168.66.177 #自定义某些域名及其子域名都解析到某一个ip地址 address=/taobao.com/192.168.66.177 #当有人访问taobao.com这个域名时,就也解析到177机器 listen-address = 192.168.66.178 #定义dnsmasq的监听地址的配置参数,这里可以是127.0.0.1,也可以是本机的局域网ip addn-hosts=/etc/dnsmasq.hosts #定义一个本地域名配置文件,需要自定义的一些域名解析记录,定义解析关系即可 log-queries #记录dns查询的日志参数 打开注释即可 #文件包含识别 conf-dir=/etc/dnsmasq.d conf-dir=/etc/dnsmasq.d,.bak conf-dir=/etc/dnsmasq.d/,*.conf dhcp-option=option:domain-search,pixelshift.ai dhcp-option-force=option:domain-search,pixelshift.ai |
6. 内部解析的地址关系
1 2 3 |
vim /etc/dnsmasq.hosts 192.168.66.178 shooter.com |
7.添加上游dns解析地址(当dnsmaq在本地找不到解析记录的时候,转而去上游查找)
1 2 3 4 |
vim /etc/resolv.dnsmasq.conf nameserver 119.29.29.29 nameserver 223.5.5.5 |
8.修改本机dns配置
1 2 |
vim /etc/resolv.conf nameserver 127.0.0.1 #这里可以是127.0.0.1,也可以是本机的局域网ip |
9.接下来启动dnsmasq
1 2 3 4 5 6 |
systemctl start dnsmasq systemctl status dnsmasq systemctl restart dnsmasq 每次修改完任何配置文件,都需要重启一下dnsmasq |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
pid-file=/var/run/dnsmasq.pid user=nobody bind-dynamic interface=br0 interface=pptp* no-dhcp-interface=pptp* no-resolv servers-file=/tmp/resolv.dnsmasq listen-address=192.168.66.178,127.0.0.1 addn-hosts=/etc/dnsmasq.hosts no-poll no-negcache cache-size=1500 min-port=4096 bogus-priv domain-needed dhcp-range=lan,192.168.66.2,192.168.66.254,255.255.255.0,86400s dhcp-option=lan,3,192.168.66.1 dhcp-option=lan,252,"\n" dhcp-authoritative dhcp-name-match=set:wpad-ignore,wpad dhcp-ignore-names=tag:wpad-ignore script-arp conf-dir=/jffs/configs/dnsmasq.d dhcp-option=option:domain-search,pixelshift.ai dhcp-option-force=option:domain-search,pixelshift.ai |
1 2 3 4 |
启动: /usr/local/sbin/dnsmasq 验证:netstat -tunlp|grep 53 关闭:killall -KILL dnsmasq 重启: pkill -9 dnsmasq && /usr/local/sbin/dnsmasq -h |
- 本文固定链接: https://www.yoyoask.com/?p=4741
- 转载请注明: shooter 于 SHOOTER 发表