dnsmasq[6120]: dnsmasq: syntax check OK.
dnsmasq[6133]: started, version 2.76 cachesize 150
dnsmasq[6133]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify
dnsmasq[6133]: no servers found in /run/dnsmasq/resolv.conf, will retry
dnsmasq[6133]: read /etc/hosts - 5 addresses
systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.
安裝 dnsmasq 之后發現無法解析域名了,nslookup 顯示請求被拒絕。dnsmasq 的日志顯示如上,提示讀取/run/dnsmasq/resolv.conf
中的域名服務器,但文件為空,搜索發現有直接修改該文件的方案,但在測試后發現該文件每次重啟 dnsmasq 服務的時候都會重新生成,修改無法保存。
dnsmasq 在默認安裝的情況下被設置為若 resolvconf 已安裝的話,則與 resolvconf 集成。這就意味着 dnsmasq 將其監聽的地址(127.0.0.1)發送給 resolvconf,並使用 resolvconf 的可用域名服務器列表生成自己的上游域名服務器列表。dnsmasq 的 resolvconf 鈎子腳本/etc/resolvconf/update.d/dnsmasq
生成/var/run/dnsmasq/resolv.conf
。這個腳本在每次 resolvconf 運行的時候觸發。
需要編輯etc/default/dnsmasq
文件,並設置IGNOR_RESOLVCONF=yes
,這樣的話 dnsmasq 就不會直接查找/var/run/dnsmasq/resolv.conf
中的內容了。
/etc/init.d/dnsmasq
:
# RESOLV_CONF:
# If the resolvconf package is installed then use the resolv conf file
# that it provides as the default.Otherwise use /etc/resolv.conf as
# the default.
#
# If IGNORE_RESOLVCONF is set in /etc/default/dnsmasq or an explicit
# filename is set there then this inhibits the use of the resolvconf-provided
# information.
#
# Note that if the resolvconf package is installed it is not possible to
# override it just by configuration in /etc/dnsmasq.conf, it is necessary
# to set IGNORE_RESOLVCONF=yes in /etc/default/dnsmasq.
if [ ! "$RESOLV_CONF" ] &;&;
[ "$IGNORE_RESOLVCONF" != "yes" ] &;&;
[ -x /sbin/resolvconf ]
then
RESOLV_CONF=/run/dnsmasq/resolv.conf
fi