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 1.1.1.1
nameserver 114.114.114.114
nameserver 8.8.8.8

5、添加 hosts

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

6、启动服务

# systemctl start dnsmasq
# systemctl enable dnsmasq

7、查看日志

# tailf /var/log/dnsmasq/dnsmasq.log
Jun 24 21:22:01 dnsmasq[4667]: started, version 2.76 cachesize 10000
Jun 24 21:22:01 dnsmasq[4667]: compile time options: IPv6 GNU-getopt DBus no-i18n IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth no-DNSSEC loop-detect inotify
Jun 24 21:22:01 dnsmasq[4667]: using nameserver 114.114.114.114#53
Jun 24 21:22:01 dnsmasq[4667]: reading /etc/resolv.dnsmasq.conf
Jun 24 21:22:01 dnsmasq[4667]: using nameserver 114.114.114.114#53
Jun 24 21:22:01 dnsmasq[4667]: using nameserver 1.1.1.1#53
Jun 24 21:22:01 dnsmasq[4667]: using nameserver 114.114.114.114#53
Jun 24 21:22:01 dnsmasq[4667]: using nameserver 8.8.8.8#53
Jun 24 21:22:01 dnsmasq[4667]: read /etc/hosts - 2 addresses
Jun 24 21:22:01 dnsmasq[4667]: read /etc/dnsmasq.hosts - 1 addresses

8、找一台机器将 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

参考:
https://hub.docker.com/r/jpillora/dnsmasq
https://www.jianshu.com/p/00254204e021
https://www.cnblogs.com/imp-W/p/12895859.html
https://shanyue.tech/op/dnsmasq.html
https://www.cnblogs.com/taoyuxuan/p/11205491.html

猜你喜欢

转载自www.cnblogs.com/keithtt/p/13190047.html