“未运行 dhcpcd,因为 /etc/network/interfaces 定义了一些将使用 DHCP 客户端或静态地址的接口”

“未运行 dhcpcd,因为 /etc/network/interfaces 定义了一些将使用 DHCP 客户端或静态地址的接口”

部署:

VM -- (eth0)RPI(wlan0) -- Router -- ISP
 ^      ^         ^         ^ 
DHCP  Static     DHCP      GW

注意:RPI 主机名:gateway

• 目标是使虚拟机能够从网络外部访问。按照教程,大功告成https://www.youtube.com/watch?v=IAa4tI4JrgI,通过路由器和 RPI 上的端口转发,通过安装 dhcpcd 并在 RPI 上配置 iptables。

• 这是我的interfaces,我在其中注释掉了 auto wlan0,试图解决该问题(之前,它没有注释,但仍然是同一件事......)

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

#auto wlan0
iface wlan0 inet dhcp
wpa-ssid FunBox-84A8
wpa-psk 7A73FA25C43563523D7ED99A4D

#auto eth0
allow-hotplug eth0
iface eth0 inet static
        address 192.168.2.1
        netmask 255.255.255.0
        network 192.168.2.0
        broadcast 192.168.2.255

• 这是firewall.conf使用的iptables

# Generated by iptables-save v1.6.0 on Sun Feb 17 20:01:56 2019
*nat
:PREROUTING ACCEPT [86:11520]
:INPUT ACCEPT [64:8940]
:OUTPUT ACCEPT [71:5638]
:POSTROUTING ACCEPT [37:4255]
-A PREROUTING -d 192.168.1.21/32 -p tcp -m tcp --dport 170 -j DNAT --to-destination 192.168.2.83:22
-A PREROUTING -d 192.168.1.21/32 -p tcp -m tcp --dport 171 -j DNAT --to-destination 192.168.2.83:443
-A PREROUTING -d 192.168.1.21/32 -p tcp -m tcp --dport 3389 -j DNAT --to-destination 192.168.2.66:3389
-A POSTROUTING -o wlan0 -j MASQUERADE
COMMIT
# Completed on Sun Feb 17 20:01:56 2019
# Generated by iptables-save v1.6.0 on Sun Feb 17 20:01:56 2019
*filter
:INPUT ACCEPT [3188:209284]
:FORWARD ACCEPT [25:2740]
:OUTPUT ACCEPT [2306:270630]
-A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o wlan0 -j ACCEPT
COMMIT
# Completed on Sun Feb 17 20:01:56 2019
# Generated by iptables-save v1.6.0 on Sun Feb 17 20:01:56 2019
*mangle
:PREROUTING ACCEPT [55445:38248798]
:INPUT ACCEPT [3188:209284]
:FORWARD ACCEPT [52257:38039514]
:OUTPUT ACCEPT [2306:270630]
:POSTROUTING ACCEPT [54565:38310208]
COMMIT
# Completed on Sun Feb 17 20:01:56 2019
# Generated by iptables-save v1.6.0 on Sun Feb 17 20:01:56 2019
*raw
:PREROUTING ACCEPT [55445:38248798]
:OUTPUT ACCEPT [2306:270630]
COMMIT
# Completed on Sun Feb 17 20:01:56 2019

iptables -L

pi@gateway:/etc$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination    

• 这里是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

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#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

denyinterfaces eth0

host Accountant {
hardware ethernet 10:60:4b:68:03:21;
fixed-address 192.168.2.83;
}

host Accountant1 {
hardware ethernet 00:0c:29:35:95:ed;
fixed-address 192.168.2.66;
}
host Accountant3 {
hardware ethernet 30:85:A9:1B:C4:8B;
fixed-address 192.168.2.70;
}

• 我无法弄清楚的错误信息:

root@gateway:/home/pi# systemctl restart dhcpcd
Warning: dhcpcd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Job for dhcpcd.service failed because the control process exited with error code.
See "systemctl status dhcpcd.service" and "journalctl -xe" for details.
root@gateway:/home/pi# systemctl status dhcpcd
● dhcpcd.service - dhcpcd on all interfaces
   Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/dhcpcd.service.d
           └─wait.conf
   Active: failed (Result: exit-code) since Sun 2019-02-17 20:36:42 GMT; 6s ago
  Process: 775 ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -w (code=exited, status=6)

Feb 17 20:36:42 gateway systemd[1]: Starting dhcpcd on all interfaces...
Feb 17 20:36:42 gateway dhcpcd[775]: Not running dhcpcd because /etc/network/interfaces
Feb 17 20:36:42 gateway dhcpcd[775]: defines some interfaces that will use a
Feb 17 20:36:42 gateway dhcpcd[775]: DHCP client or static address
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Control process exited, code=exited status=6
Feb 17 20:36:42 gateway systemd[1]: Failed to start dhcpcd on all interfaces.
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Unit entered failed state.
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Failed with result 'exit-code'.
Warning: dhcpcd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
root@gateway:/home/pi#               
root@gateway:/home/pi# systemctl daemon-reload
root@gateway:/home/pi# systemctl status dhcpcd
● dhcpcd.service - dhcpcd on all interfaces
   Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/dhcpcd.service.d
           └─wait.conf
   Active: failed (Result: exit-code) since Sun 2019-02-17 20:36:42 GMT; 1min 23s ago

Feb 17 20:36:42 gateway systemd[1]: Starting dhcpcd on all interfaces...
Feb 17 20:36:42 gateway dhcpcd[775]: Not running dhcpcd because /etc/network/interfaces
Feb 17 20:36:42 gateway dhcpcd[775]: defines some interfaces that will use a
Feb 17 20:36:42 gateway dhcpcd[775]: DHCP client or static address
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Control process exited, code=exited status=6
Feb 17 20:36:42 gateway systemd[1]: Failed to start dhcpcd on all interfaces.
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Unit entered failed state.
Feb 17 20:36:42 gateway systemd[1]: dhcpcd.service: Failed with result 'exit-code'.
root@gateway:/home/pi#       

gateway版本:

pi@gateway:/etc$ cat os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian

问题:

1)错误信息是什么Not running dhcpcd because /etc/network/interfaces defines some interfaces that will use a DHCP client or static address意思?根据我上面的配置如何修复它?

2)为什么主机没有根据我的 dhcpcd.conf 分配 IP 地址,除了主机之外Accountant,它总是获得我想要的相同 IP,即使注释掉绑定...?如何解决这个问题,以便能够将多个主机的 MAC 与 IP 绑定?

3)这个符号的含义是什么:

#auto eth0
allow-hotplug eth0
iface eth0 inet static
        address 192.168.2.1
        netmask 255.255.255.0
        network 192.168.2.0
        broadcast 192.168.2.255

interfacesLinux 中文件的表示规则是什么?

答案1

问题 1.) 抱歉,您似乎误解了一些事情。

dhcpcd是一个 DHCP客户守护进程,通常由 NetworkManager 或 启动ifupdown,而不是直接由 启动systemd。它将负责为您的wlan0.

dhcpcd如果您愿意,请按照开始使用systemd,但是这将需要禁用发行版的所有正常网络接口配置逻辑(即/etc/network/interfaces必须为空的非注释行),并在必要时用您自己的自定义脚本替换它。仅限特殊用途;如果你不能绝对确定你应该这样做,那么你就不应该这样做。

dhcpcd永远不会为任何其他主机提供 IP 地址。您添加的这部分dhcpcd.conf看起来属于 ISC DHCP 的配置文件服务器守护进程,dhcpd(是的,只是一个字母的区别):

host Accountant {
hardware ethernet 10:60:4b:68:03:21;
fixed-address 192.168.2.83;
}

host Accountant1 {
hardware ethernet 00:0c:29:35:95:ed;
fixed-address 192.168.2.66;
}
host Accountant3 {
hardware ethernet 30:85:A9:1B:C4:8B;
fixed-address 192.168.2.70;
}

但是,如果您正在遵循您提到的 YouTube 教程,您甚至可能还没有dhcpd安装,因为dnsmasq应该完成这项工作。

据我所知,等效语法dnsmasq.conf是:

dhcp-host=10:60:4b:68:03:21,192.168.2.83,Accountant
dhcp-host=00:0c:29:35:95:ed,192.168.2.66,Accountant1
dhcp-host=30:85:A9:1B:C4:8B,192.168.2.70,Accountant3

免责声明:我实际上没有使用过dnsmasq,所以这是基于快速谷歌搜索其手册页。


问题 2.) 在您提到的教程中,dnsmasq应该充当eth0.你没有说任何事情,所以我不知道它是否正在运行。如果不是,始终获得相同 IP 的一个客户端可能只是退回到先前收到的尚未过期的旧 DHCP 租约。是的,如果网络似乎没有可用的工作 DHCP 服务器,DHCP 客户端可能会永久存储 DHCP 租约并继续使用它。


问题3.):/etc/network/interfaces是一个经典的Debian/Ubuntu风格的网络接口配置文件。用于man interfaces查看它的文档,或者看这里。

在 Debian、*Ubuntu、Raspbian 等中,NetworkManager 将有一个插件,可以 /etc/network/interfaces但不会到它。

如果使用 NetworkManager 配置工具(例如 、 )nmclinmtui您选择的桌面环境中基于 GUI 的 NetworkManager 配置工具,则配置将保存到目录中的/etc/NetworkManager/system-connections/文件中。

如果未安装 NetworkManager,该/etc/network/interfaces文件将由包使用ifupdown,其中包括命令ifupifdown.该软件包还包括一个系统启动脚本,该脚本将ifup -a在启动时运行,从而auto <interface name>启用/etc/network/interfaces.还有一个 udev 规则,ifup <interface name>如果新网络接口的驱动程序自动加载并/etc/network/interfaces有一条allow-hotplug <interface name>线,该规则将运行。

答案2

我找到了这个“错误”的原因。

dhcpcd使用某种“菜鸟/新手保护”,如果某些“菜鸟/新手”尝试同时使用dhcpcd和,则可以保证以安全的方式处理网络管理/etc/interfaces

dhcpcd/etc/interfaces使用以下 shell 脚本检查/usr/lib/dhcpcd5/dhcpcd

#!/bin/sh -e

DHCPCD=/sbin/dhcpcd
INTERFACES=/etc/network/interfaces

if grep -q -E "^[[:space:]]*iface[[:space:]]*.*[[:space:]]*inet[[:space:]]*(dhcp|static)" \
                $INTERFACES; then
        echo "Not running dhcpcd because $INTERFACES"
        echo "defines some interfaces that will use a"
        echo "DHCP client or static address"
        exit 6
fi

exec $DHCPCD $@

我只是交替线路

if grep -q -E "^[[:space:]]*iface[[:space:]]*.*[[:space:]]*inet[[:space:]]*(dhcp|static)" \

通过删除|static参数,

if grep -q -E "^[[:space:]]*iface[[:space:]]*.*[[:space:]]*inet[[:space:]]*(dhcp)" \

并将最后一条回声线调整为:

echo "DHCP client"

聚苯乙烯确保添加一个denyinterfaces "NAME OF YOUR STATIC INTERFACE, WHICH SHALL BE CONTROLLED ONLY BY /etc/interfaces", 例如denyinterfaces eth0到您的/etc/dhcpcd.conf.

相关内容