2019独角兽企业重金招聘Python工程师标准>>>
树梅派DNS缓存服务器建设
Hradware: 树梅派3B+
OS: Debian Gnu/Linux 9.4
安装软件:
apt-get dnsmasq
参数配置:
配置网络(无线接入):
vi /etc/wpa_supplicant/wpa_supplicant.conf
加入无线节点SSID及链接密码信息,格式如下:
network={
ssid="demotest"
psk="demotest"
}
vi /etc/dhcpcd.conf
修改如下行为需要的内容:
interface wlan0
static ip_address=192.168.0.7/24
static routers=192.168.0.1
vi /etc/dhcp/dhclient.conf
将“#prepend domain-name-servers 127.0.0.1;”行内容前的“#”号删除。
vi /etc/resolv.dnsmasq.conf
增加如下行(用户可根据自己的DNS添加):
nameserver 223.5.5.5
nameserver 223.6.6.6
nameserver 114.114.114.114
vi /etc/dnsmasq.conf
确保如下行存在:
domain-needed
resolv-file=/etc/resolv.dnsmasq.conf
all-servers
问题处理:
重启后dnsmasq服务报如下错误:
2月 28 16:34:10 localhost dnsmasq[346]: no servers found in /run/dnsmasq/resolv.conf, will retry
2月 28 16:34:11 localhost dnsmasq[347]: Too few arguments.
需要修改/etc/default/dnsmasq文件并将“#IGNORE_RESOLVCONF=yes”前的“#”删除即可。
网上原贴(原文引自:https://memo.ink/dnsmasq-resolv-conf/)如下:
1
2
3
4
5
6
7 |
systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
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
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
# 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 |
自觉原创,所以大赏,多少我都心存感激