1、安装
yum install dnsmasq
2、配置
2.1、修改/etc/dnsmasq.conf
vim /etc/dnsmasq.conf
#dnsmasq 会从这个文件中寻找上游dns服务器
resolv-file=/etc/resolv.dnsmasq.conf
#去掉前面的#,表示resolv-file 对应的文件中dns 会安装顺序找上游dns
strict-order
#在这个目里面添加 ip 域名 记录 指定域名解析记录
addn-hosts=/etc/dnsmasq.hosts
#监听地址 去掉就是任意服务器都能访问 此dns, 如果写这个 192.168.1.123 表示只有这个网段才能访问此dns
#listen-address=127.0.0.1,192.168.1.123 保持注释掉
2.2、修改/etc/resolv.conf
echo 'nameserver 127.0.0.1' > /etc/resolv.conf
2.3、touch /etc/resolv.dnsmasq.conf
#添加上游的DNS服务器,也就是公网DNS,这里添加阿里云的,或者114
echo 'nameserver 223.5.5.5' >> /etc/resolv.dnsmasq.conf
echo 'nameserver 223.6.6.6' >> /etc/resolv.dnsmasq.conf
echo 'nameserver 114.114.114.114' >> /etc/resolv.dnsmasq.conf
echo 'nameserver 114.114.115.115' >> /etc/resolv.dnsmasq.conf
2.4、创建/etc/dnsmasq.hosts
cp /etc/hosts /etc/dnsmasq.hosts
127.0.0.1 localhost localhost localdomain localhost localhost. localdomain4
:1
localhostlocalhost localdomain localhost localhost. localdomain6
# 以下添加了多个 域名以这种形式: ip 域名
192.199.3.25 milo1.com
192.189.3.206 menlo2.com
192.108.3.287 mInlo3.com
192.108.3.57 mInlo4.com
192.168.21.184 menlo5.com
192.168.21.195 milo6.com
192.168.21.146 mInlo7.com
192.168.21.19 mnlo8.com
3、启动
systemctl start dnsmasq
systemctl status dnsmasq
systemctl enable dnsmasq
4、客户端使用
配置dns服务器地址
[root@n] cat /etc/resolv. conf
nameserver 192.100.3.240