这是Ubuntu 20.04。
我停止并禁用了 systemd-networkd。然后启用NetworkManager。但重启后这两个服务都会出现。这样的事情不断发生。我想使用 nmcli 管理我的服务器,但不确定如何让它工作(并停止联网)
349 systemctl stop systemd-networkd
350 nmcli dev status
351 systemctl restart network-manager
352 systemctl status network-manager
364 systemctl status systemd-networkd
365 systemctl disable systemd-networkd
366 systemctl status NetworkManager
367 systemctl enable NetworkManager
---重启后----
# ls -ltr /run/network/
total 4
-rw-r--r-- 1 root root 88 Feb 3 21:50 dynamic-interfaces
# nmcli dev status
DEVICE TYPE STATE CONNECTION
eno1 ethernet unmanaged --
eno2 ethernet unmanaged --
eno3 ethernet unmanaged --
eno4 ethernet unmanaged --
enp129s0f0 ethernet unmanaged --
enp129s0f1 ethernet unmanaged --
enp131s0f0 ethernet unmanaged --
enp131s0f1 ethernet unmanaged --
enp3s0f0 ethernet unmanaged --
enp3s0f1 ethernet unmanaged --
idrac ethernet unmanaged --
lo loopback unmanaged --
我现在可以使用 DHCP 从 eno1 上的网络通过 ssh 登录主机,但稍后希望将其设为静态。
# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
inet x.x.x.x/24 brd x.x.x.x scope global dynamic eno1
valid_lft 28733sec preferred_lft 28733sec
3: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
4: eno3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
5: eno4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
6: enp3s0f0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
7: enp129s0f0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
8: enp3s0f1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
9: enp129s0f1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
10: enp131s0f0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
11: enp131s0f1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
12: idrac: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
root@myhost:~#
root@myhost:~# systemctl status systemd-networkd
● systemd-networkd.service - Network Service
Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled-runtime; vendor preset: enabled)
Active: active (running) since Fri 2023-02-03 21:51:06 UTC; 8min ago
Docs: man:systemd-networkd.service(8)
Main PID: 1611 (systemd-network)
Status: "Processing requests..."
Tasks: 1 (limit: 309305)
Memory: 4.1M
CGroup: /system.slice/systemd-networkd.service
└─1611 /lib/systemd/systemd-networkd
Feb 03 21:51:06 myhost systemd[1]: Starting Network Service...
Feb 03 21:51:06 myhost systemd-networkd[1611]: Enumeration completed
Feb 03 21:51:06 myhost systemd[1]: Started Network Service.
Feb 03 21:51:06 myhost systemd-networkd[1611]: eno1: Link UP
Feb 03 21:51:07 myhost systemd-networkd[1611]: eno1: Gained carrier
Feb 03 21:51:07 myhost systemd-networkd[1611]: eno1: DHCPv4 address x.x.x.x/24 via x.x.x.x
root@myhost:~#
root@myhost:~# systemctl status NetworkManager
● NetworkManager.service - Network Manager
Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-02-03 21:51:10 UTC; 8min ago
Docs: man:NetworkManager(8)
Main PID: 1639 (NetworkManager)
Tasks: 3 (limit: 309305)
Memory: 14.9M
CGroup: /system.slice/NetworkManager.service
└─1639 /usr/sbin/NetworkManager --no-daemon
Feb 03 21:51:10 myhost NetworkManager[1639]: <info> [1675461070.5034] manager: (enp3s0f1): new Ethernet device (/or>
Feb 03 21:51:10 myhost NetworkManager[1639]: <info> [1675461070.5050] manager: (idrac): new Ethernet device (/org/f>
Feb 03 21:51:10 myhost NetworkManager[1639]: <warn> [1675461070.5286] Error: failed to open /run/network/ifstate
Feb 03 21:51:10 myhost NetworkManager[1639]: <info> [1675461070.5634] manager: startup complete
Feb 03 21:51:10 myhost NetworkManager[1639]: <info> [1675461070.8076] modem-manager: ModemManager not available
Feb 03 21:51:10 myhost NetworkManager[1639]: <info> [1675461070.8842] modem-manager: ModemManager now available
Feb 03 21:52:43 myhost NetworkManager[1639]: <info> [1675461163.2859] manager: rfkill: Wi-Fi hardware radio set dis>
Feb 03 21:52:43 myhost NetworkManager[1639]: <info> [1675461163.2862] audit: op="radio-control" arg="wireless-enabl>
Feb 03 21:58:03 myhost NetworkManager[1639]: <info> [1675461483.8856] manager: rfkill: WWAN hardware radio set disa>
Feb 03 21:58:03 myhost NetworkManager[1639]: <info> [1675461483.8858] audit: op="radio-control" arg="wwan-enabled" >
root@myhost:~#
从那时起我就这样做了:
到目前为止我所理解的最好的修改了这个文件:
# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity' (<----from cloud-init of live dvd install....)
network:
ethernets:
eno1:
addresses: [x.x.x.x/24]
gateway4: x.x.x.x
nameservers:
addresses: [xx.x.x.x]
version: 2
# netplan apply
# nmcli c s
# nmcli d s
DEVICE TYPE STATE CONNECTION
eno1 ethernet unmanaged --
eno2 ethernet unmanaged --
eno3 ethernet unmanaged --
eno4 ethernet unmanaged --
enp129s0f0 ethernet unmanaged --
enp129s0f1 ethernet unmanaged --
enp131s0f0 ethernet unmanaged --
enp131s0f1 ethernet unmanaged --
enp3s0f0 ethernet unmanaged --
enp3s0f1 ethernet unmanaged --
idrac ethernet unmanaged --
lo loopback unmanaged --
#
ip addr 现在是静态的,但 nmcli 仍然无法管理它......并且我的路由表似乎已更改。
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 24:6e:96:06:f2:f8 brd ff:ff:ff:ff:ff:ff
inet x.x.x.x/24 brd x.x.x.x scope global eno1
valid_lft forever preferred_lft forever
如果我停止 systemd-networkd 然后运行 netplan apply 我会收到错误:
# systemctl stop systemd-networkd
# netplan apply
Failed to reload network settings: No such file or directory
Falling back to a hard restart of systemd-networkd.service
然后我尝试了你的建议:
# systemctl stop systemd-networkd
# systemctl disable systemd-networkd
# systemctl mask systemd-networkd
Created symlink /etc/systemd/system/systemd-networkd.service → /dev/null.
# systemctl restart NetworkManager
现在它完全疯了:
# netplan apply
Failed to reload network settings: No such file or directory
Falling back to a hard restart of systemd-networkd.service
Failed to restart systemd-networkd.service: Unit systemd-networkd.service is masked.
Traceback (most recent call last):
File "/usr/share/netplan/netplan/cli/commands/apply.py", line 265, in command_apply
utils.networkctl_reload()
File "/usr/share/netplan/netplan/cli/utils.py", line 103, in networkctl_reload
subprocess.check_call(['networkctl', 'reload'])
File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['networkctl', 'reload']' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/sbin/netplan", line 23, in <module>
netplan.main()
File "/usr/share/netplan/netplan/cli/core.py", line 50, in main
self.run_command()
File "/usr/share/netplan/netplan/cli/utils.py", line 247, in run_command
self.func()
File "/usr/share/netplan/netplan/cli/commands/apply.py", line 61, in run
self.run_command()
File "/usr/share/netplan/netplan/cli/utils.py", line 247, in run_command
self.func()
File "/usr/share/netplan/netplan/cli/commands/apply.py", line 275, in command_apply
utils.systemctl('restart', ['systemd-networkd.service'], sync=True)
File "/usr/share/netplan/netplan/cli/utils.py", line 89, in systemctl
subprocess.check_call(command)
File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['systemctl', 'restart', 'systemd-networkd.service']' returned non-zero exit status 1.
我试图废除除 nmcli / NetworkManager 之外的所有内容。这变得太复杂了。
答案1
通常运行
systemctl disable foo.service
仅撤消[Install]
单元文件的部分。它仍然可以通过其他 systemd 单元的需求或依赖项来执行。
如果您想阻止该服务运行,您需要运行
systemctl mask foo.service
这将使用 /etc 中 /dev/null 的符号链接覆盖单元文件,因此它无法运行。
答案2
我在 netplan 配置中添加了渲染器指令,它解决了该问题。现在我可以(我做到了)蒙面联网。并重新启动网络管理器。现在一切都在纳米之下。
答案3
正如您自己提到的,解决方案是将渲染器添加到 netplan 配置文件中。原因是 netplan 使用的默认渲染器是 systemd-networkd,根据以下文档: https://netplan.io/reference
分发安装程序、云实例化、特定设备的映像构建或部署操作系统的任何其他方式将其所需的网络配置放入 YAML 配置文件中。在早期启动期间,netplan“网络渲染器”运行,它读取 /{lib,etc,run}/netplan/*.yaml 并将配置写入 /run 以将对设备的控制权移交给指定的网络守护进程。
- 配置的设备默认由 systemd-networkd 处理,除非明确标记为由特定渲染器 (NetworkManager) 管理