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
https://blog.csdn.net/weixin_34248258/article/details/92926584
https://public-dns.info/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM