樹梅派DNS快取伺服器建設
樹梅派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 |
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 |
自覺原創,所以大賞,多少我