CentOS7 上部署 dnsmasq

1、安装 dnsmasq

yum install -y dnsmasq

2、修改配置

$ grep -v '^#' /etc/dnsmasq.conf |grep -v '^$'

resolv-file=/etc/resolv.dnsmasq.conf
strict-order
server=114.114.114.114
listen-address=172.20.72.7,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-file

$ vim /etc/resolv.dnsmasq.conf
nameserver 114.114.114.114
nameserver 1.0.0.1
nameserver 1.1.1.1

5、添加 hosts

$ vim /etc/dnsmasq.hosts
123.206.16.61  www.psy.com

6、启动服务

systemctl enable dnsmasq --now

7、找一台机器将 dns 指向 dnsmasq 服务器地址

$ vim /etc/resolv.conf

nameserver 127.0.0.1
$ nslookup

> www.psy.com
Server:		127.0.0.1
Address:	127.0.0.1#53

Name:	www.psy.com
Address: 123.206.16.61
> www.baidu.com
Server:		114.114.114.114
Address:	114.114.114.114#53

Non-authoritative answer:
www.baidu.com	canonical name = www.a.shifen.com.
Name:	www.a.shifen.com
Address: 61.135.169.121
Name:	www.a.shifen.com
Address: 61.135.169.125

参考文档

posted @ 2020-06-24 21:35  KeithTt  阅读(1098)  评论(0编辑  收藏  举报