我有一台运行 Ubuntu Server 18.04 的机器。网络是使用 Netplan 配置的,所以我有这个配置/etc/netplan/01-netcfg.yaml
:
network:
version: 2
renderer: networkd
ethernets:
enp1s0f0:
optional: false
addresses:
- 10.0.0.1/24
wifis:
wlp2s0:
optional: true
dhcp4: yes
access-points:
[...]
enp1s0f0
连接到可能打开或未打开的设备(在启动时或任何其他时间)。我想在这个接口上运行一个 DHCP 服务器。
问题是,当我启动时有几分钟的延迟,我看到这条消息:
A start job is running for Wait for Network to be Configured
最终超时,引导继续,但enp1s0f0
从未配置或启动。ip link show enp1s0f0
给出:
2: enp1s0f0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
link/ether 10:dd:b1:ef:65:21 brd ff:ff:ff:ff:ff:ff
我不知道它的意义NO-CARRIER
是什么,但如果它是相关的,这里是输出sudo lspci -v
:
01:00.0 Ethernet controller: Broadcom Limited NetXtreme BCM57766 Gigabit Ethernet PCIe (rev 01)
Subsystem: Broadcom Limited NetXtreme BCM57766 Gigabit Ethernet PCIe
Flags: bus master, fast devsel, latency 0, IRQ 16
Memory at a0400000 (64-bit, prefetchable) [size=64K]
Memory at a0410000 (64-bit, prefetchable) [size=64K]
Capabilities: [48] Power Management version 3
Capabilities: [50] Vital Product Data
Capabilities: [58] MSI: Enable- Count=1/8 Maskable- 64bit+
Capabilities: [a0] MSI-X: Enable+ Count=6 Masked-
Capabilities: [ac] Express Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Capabilities: [13c] Device Serial Number 00-00-10-dd-b1-ef-65-21
Capabilities: [150] Power Budgeting <?>
Capabilities: [160] Virtual Channel
Capabilities: [1b0] Latency Tolerance Reporting
Kernel driver in use: tg3
Kernel modules: tg3
现在,如果我打开连接的设备,肯定enp1s0f0
会出现:
2: enp1s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 10:dd:b1:ef:65:21 brd ff:ff:ff:ff:ff:ff
但此时它没有用——DHCP 服务器将无法工作,因为它enp1s0f0
在启动时无法启动。我需要enp1s0f0
在启动过程中启动和配置,我认为这是静态 IP 配置的重点。更奇怪的是它总是有一个 IPv6 地址,即使它关闭了:
2: enp1s0f0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether 10:dd:b1:ef:65:21 brd ff:ff:ff:ff:ff:ff
inet6 fe80::12dd:b1ff:feef:6521/64 scope link
valid_lft forever preferred_lft forever
如果我检查 Netplan 的调试输出,我会看到:
$ sudo netplan --debug apply
** (generate:1555): DEBUG: 20:39:27.253: Processing input file //etc/netplan/01-netcfg.yaml..
** (generate:1555): DEBUG: 20:39:27.254: starting new processing pass
** (generate:1555): DEBUG: 20:39:27.254: wlp2s0: adding wifi AP 'Jeff Winger's Wireless Hairbrush'
** (generate:1555): DEBUG: 20:39:27.254: wlp2s0: setting default backend to 1
** (generate:1555): DEBUG: 20:39:27.254: enp1s0f0: setting default backend to 1
** (generate:1555): DEBUG: 20:39:27.254: Generating output files..
** (generate:1555): DEBUG: 20:39:27.254: wlp2s0: Creating wpa_supplicant configuration file run/netplan/wpa-wlp2s0.conf
** (generate:1555): DEBUG: 20:39:27.254: Creating wpa_supplicant service enablement link /run/systemd/system/multi-user.target.wants/[email protected]
** (generate:1555): DEBUG: 20:39:27.254: NetworkManager: definition wlp2s0 is not for us (backend 1)
** (generate:1555): DEBUG: 20:39:27.254: NetworkManager: definition enp1s0f0 is not for us (backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:replug enp1s0f0: unbinding 0000:01:00.0 from /sys/bus/pci/drivers/tg3
DEBUG:replug enp1s0f0: rebinding 0000:01:00.0 to /sys/bus/pci/drivers/tg3
DEBUG:device wlp2s0 operstate is up, not replugging
DEBUG:netplan triggering .link rules for wlp2s0
DEBUG:device lo operstate is unknown, not replugging
DEBUG:netplan triggering .link rules for lo
我的配置isc-dhcp-server
是/etc/default/isc-dhcp-server
包含:
INTERFACESv4="enp1s0f0"
...并/etc/dhcp/dhcpd.conf
包含(除其他外):
subnet 10.0.0.0 netmask 255.255.255.0 {
...
}
理论上,这应该服务于 DHCP over enp1s0f0
。但是,由于enp1s0f0
从未启动,DHCP 服务器无法启动:
No subnet declaration for enp1s0f0 (no IPv4 addresses).
** Ignoring requests on enp1s0f0. If this is not what
you want, please write a subnet declaration
in your dhcpd.conf file for the network segment
to which interface enp1s0f0 is attached. **
Not configured to listen on any interfaces!
这不是问题ifupdown
(我不知道为什么enp1s0f0
不只是在启动期间出现,无论电缆的另一端是否有任何东西;我认为这就是拥有静态 IP 的全部意义)。是否有可能让它在 Netplan 中工作?或者是否可以让 DHCP 服务器在启动时enp1s0f0
启动?
看起来您遇到了将由https://github.com/CanonicalLtd/netplan/pull/34解决的错误- 目前,只有在有运营商的情况下才会配置设备,但该要求正在消失。
同时,您可以通过
systemd-networkd
直接配置设备来解决此问题。enp1s0f0
从 netplan 配置中删除该节,并在以下位置添加类似(未经测试)的 systemd 配置/etc/systemd/network/10-enp1s0f0.network
:关键位是
ConfigureWithoutCarrier
我直接从拉取请求中提取的。(您可以查看 netplan 生成的内容并从那里开始 - 文件将位于
/run/systemd/network
.)或者,您可以利用 netplan 和 ifupdown 可以共存的事实,并使用 ifupdown 进行
apt install ifupdown
配置enp1s0f0
。看起来 Netplan 有一个智能系统,可以判断 iface 何时有链接,并仅在链接启动时自动分配地址。
当该接口没有链接(载波信号)时,它仍然未配置,但是,如果我打开电缆另一端的另一个设备,该接口会自动使用 IP 地址和它需要的一切来启动它。
对于 DHCP,解决方案是不将其绑定到特定接口......