将 Raspberry Pi 配置为 DHCP/本地 DNS 服务器,Stretch 与 Wheezy

将 Raspberry Pi 配置为 DHCP/本地 DNS 服务器,Stretch 与 Wheezy

多年来,我一直在旧的 Raspberry Pi 上使用 dnsmasq 作为 DHCP 服务器/解析器,运行 wheezy,没有任何问题。我决定升级到 stretch,同时升级到 Raspberry Pi 3B+。

不幸的是,我很难配置新的 Pi 以提供与旧 Pi 相同的 DHCP 和 DNS 服务。我使用 dnsmasq 提供这两项服务。我可以配置新的 Pi 以使其正常工作,当它不提供 DHCP/DNS 服务,而是从旧 Pi 获取这些服务时。但是当我尝试让它提供这些服务时,我失去了与互联网的连接。感觉好像我搞砸了网关的配置,虽然我不知道怎么做,而且我知道如何运行的诊断程序似乎没有显示网关有问题。

在旧的 Pi 上,运行 wheezy,我在 /etc/network/interfaces 中配置了以太网接口,如下所示:

iface eth0 inet static
address 10.0.0.4
netmask 255.255.255.0
gateway 10.0.0.2

在新的 Pi 上,运行 stretch,我在 dhcpcd.conf 中配置以太网接口(请注意,我在这里使用不同的静态 IP 地址,因此当我尝试转换到新设备时,两个设备不会发生冲突):

interface eth0
static ip_address=10.0.0.5/24
static routers=10.0.0.2

如果我运行新的 Pi 独立版,我会注释掉这三行,因为新的 Pi 会从旧的 Pi 获取其 IP 地址。

在 stretch 下,启动过程似乎涉及 resolvconf 和 dhcpcd 重写 /etc/resolv.conf。此外,resolvconf 在 /run/dnsmasq/resolv.conf 处创建一个单独的 resolv.conf 文件...这两个文件并不相同。我也不明白为什么会有两个单独的文件,以及每个文件起什么作用。

这是启动后的 /etc/resolv.conf:

# Generated by resolvconf
nameserver 127.0.0.1
# external nameservers
nameserver 8.8.8.8
nameserver 8.8.4.4

这是 /run/dnsmasq/resolv.conf:

# Generated by resolvconf

这是resolvconf.conf:

# Configuration for resolvconf(8)
# See resolvconf.conf(5) for details

resolv_conf=/etc/resolv.conf
# If you run a local name server, you should uncomment the below line and
# configure your subscribers configuration files below.
name_servers=127.0.0.1, 8.8.8.8, 8.8.4.4

# Mirror the Debian package defaults for the below resolvers
# so that resolvconf integrates seemlessly.
dnsmasq_resolv=/var/run/dnsmasq/resolv.conf
pdnsd_conf=/etc/pdnsd.conf
unbound_conf=/var/cache/unbound/resolvconf_resolvers.conf

resolv.conf.tail:

# external nameservers
nameserver 8.8.8.8
nameserver 8.8.4.4

和 dhcpcd.conf:

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# This section needs to be live if mycroft is serving as
# the DHCP server for the LAN. Conversely, if it isn't
# serving in that role, it needs to be commented out.
interface eth0
static ip_address=10.0.0.5/24
static routers=10.0.0.2
#static domain_name_servers=127.0.0.1,8.8.8.8,8.8.4.4

# not using ip6!
#static ip6_address=fd51:42f8:caae:d92e::ff/64

# domain name servers specified in resolv.conf.tail
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

有什么建议吗?

相关内容