1、安装 dnsmasq
yum install -y dnsmasq
2、修改配置
# 备份dnsmasq.conf
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
# 清空文件内容
echo > /etc/dnsmasq.conf
# 写入以下内容
resolv-file=/etc/resolv.dnsmasq.conf
strict-order
server=114.114.114.114
# listen-address写自己的服务器IP
listen-address=192.168.10.200,127.0.0.1
addn-hosts=/etc/dnsmasq.hosts
cache-size=10240
bogus-nxdomain=114.114.114.114
log-queries
log-facility=/var/log/dnsmasq/dnsmasq.log
conf-dir=/etc/dnsmasq.d
conf-dir=/etc/dnsmasq.d,.bak
conf-dir=/etc/dnsmasq.d/,*.conf
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig
3、创建日志目录
mkdir /var/log/dnsmasq/
4、修改 resolv.dnsmasq.conf
vim /etc/resolv.dnsmasq.conf
# 内容如下
nameserver 114.114.114.114
nameserver 1.0.0.1
nameserver 1.1.1.1
5、添加 hosts
# 添加自己要解析的IP和域名
vim /etc/dnsmasq.hosts
192.168.10.33 www.testdns.com
6、启动服务并加入开机启动
systemctl start dnsmasq
systemctl enable dnsmasq
7、客户端机器要通过指定的域名正常访问,需要将本机的DNS手动设置为搭建dnsmasq的服务器IP上
linux设置DNS
vim /etc/resolv.conf
nameserver 192.168.10.200
mac设置DNS(下面是脚本内容)
#!/usr/bin/env bash
networksetup -setdnsservers Wi-Fi 192.168.10.200
windows设置DNS(下面是脚本内容),可以手动设置,也可以执行脚本
@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
cd /d "%~dp0"
netsh interface ipv4 set dns name="以太网" source=static addr=172.17.73.120 register=PRIMARY
netsh interface ipv4 set dns name="WLAN" source=static addr=172.17.73.120 register=PRIMARY
ipconfig /all
::pause
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/281991.html