参考
参考文献

1、安装

yum install dnsmasq

2、配置

2.1、修改/etc/dnsmasq.conf

vim /etc/dnsmasq.conf

  1. #dnsmasq 会从这个文件中寻找上游dns服务器
  2. resolv-file=/etc/resolv.dnsmasq.conf
  3. #去掉前面的#,表示resolv-file 对应的文件中dns 会安装顺序找上游dns
  4. strict-order
  5. #在这个目里面添加 ip 域名 记录 指定域名解析记录
  6. addn-hosts=/etc/dnsmasq.hosts
  7. #监听地址 去掉就是任意服务器都能访问 此dns, 如果写这个 192.168.1.123 表示只有这个网段才能访问此dns
  8. #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

  1. #添加上游的DNS服务器,也就是公网DNS,这里添加阿里云的,或者114
  2. echo 'nameserver 223.5.5.5' >> /etc/resolv.dnsmasq.conf
  3. echo 'nameserver 223.6.6.6' >> /etc/resolv.dnsmasq.conf
  4. echo 'nameserver 114.114.114.114' >> /etc/resolv.dnsmasq.conf
  5. echo 'nameserver 114.114.115.115' >> /etc/resolv.dnsmasq.conf

2.4、创建/etc/dnsmasq.hosts

cp /etc/hosts /etc/dnsmasq.hosts

  1. 127.0.0.1 localhost localhost localdomain localhost localhost. localdomain4
  2. :1
  3. localhostlocalhost localdomain localhost localhost. localdomain6
  4. # 以下添加了多个 域名以这种形式: ip 域名
  5. 192.199.3.25 milo1.com
  6. 192.189.3.206 menlo2.com
  7. 192.108.3.287 mInlo3.com
  8. 192.108.3.57 mInlo4.com
  9. 192.168.21.184 menlo5.com
  10. 192.168.21.195 milo6.com
  11. 192.168.21.146 mInlo7.com
  12. 192.168.21.19 mnlo8.com

3、启动

  1. systemctl start dnsmasq
  2. systemctl status dnsmasq
  3. systemctl enable dnsmasq

4、客户端使用

配置dns服务器地址

  1. [root@n] cat /etc/resolv. conf
  2. nameserver 192.100.3.240