在我的安装好的系统中,网卡默认配置为 DHCP 方式获取 IP 地址,/etc/network/interfaces 内容如下:
# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).source/etc/network/interfaces.d/*# The loopback network interfaceautoloifaceloinetloopback# The primary network interfaceallow-hotplugens33ifaceens33inetdhcp
root@debian:~# apt install network-manager
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
crda dns-root-data dnsmasq-base iw libbluetooth3 libgudev-1.0-0 libjansson4
libjim0.77 libmbim-glib4 libmbim-proxy libmm-glib0 libndp0 libnl-3-200
libnl-genl-3-200 libnl-route-3-200 libnm0 libpcap0.8 libpcsclite1
libpolkit-agent-1-0 libpolkit-backend-1-0 libpolkit-gobject-1-0 libqmi-glib5
libqmi-proxy libteamdctl0 modemmanager policykit-1 ppp usb-modeswitch
usb-modeswitch-data wireless-regdb wpasupplicant
Suggested packages:
pcscd libteam-utils comgt wvdial wpagui libengine-pkcs11-openssl
The following NEW packages will be installed:
crda dns-root-data dnsmasq-base iw libbluetooth3 libgudev-1.0-0 libjansson4
libjim0.77 libmbim-glib4 libmbim-proxy libmm-glib0 libndp0 libnl-3-200
libnl-genl-3-200 libnl-route-3-200 libnm0 libpcap0.8 libpcsclite1
libpolkit-agent-1-0 libpolkit-backend-1-0 libpolkit-gobject-1-0 libqmi-glib5
libqmi-proxy libteamdctl0 modemmanager network-manager policykit-1 ppp
usb-modeswitch usb-modeswitch-data wireless-regdb wpasupplicant
0 upgraded, 32 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,152 kB of archives.
After this operation, 31.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.163.com/debian buster/main amd64 libbluetooth3 amd64 5.50-1.2~deb10u1 [100 kB]
Get:2 http://mirrors.163.com/debian buster/main amd64 libjansson4 amd64 2.12-1 [38.0 kB]
Get:3 http://mirrors.163.com/debian buster/main amd64 libmm-glib0 amd64 1.10.0-1 [942 kB]
--- # 省略部分输出
Setting up libqmi-proxy (1.22.0-1.2) ...
Setting up network-manager (1.14.6-2+deb10u1) ...
The following network interfaces were found in /etc/network/interfaces
which means they are currently configured by ifupdown:
- ens33
If you want to manage those interfaces with NetworkManager instead
remove their configuration from /etc/network/interfaces.
Created symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service →
/lib/systemd/system/NetworkManager-dispatcher.service.
Created symlink /etc/systemd/system/network-online.target.wants/NetworkManager-w
ait-online.service → /lib/systemd/system/NetworkManager-wait-online.service.
Created symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.servi
ce → /lib/systemd/system/NetworkManager.service.
Setting up modemmanager (1.10.0-1) ...
Created symlink /etc/systemd/system/dbus-org.freedesktop.ModemManager1.service →
/lib/systemd/system/ModemManager.service.
Created symlink /etc/systemd/system/multi-user.target.wants/ModemManager.service
→ /lib/systemd/system/ModemManager.service.
Processing triggers for systemd (241-7~deb10u5) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for dbus (1.12.20-0+deb10u1) ...
Processing triggers for libc-bin (2.28-10) ...
root@debian:~#
但 NetworkManager 会覆盖已有的所有网络配置,包括 DNS 在内,因此所有配置要使用 NetworkManager 配套工具进行。
如果要整体对网络管理器进行迁移,需要进行一番操作。
在继续使用之前,我们将原配置文件的网卡配置注释。
$ root@debian:~# vi /etc/network/interfaces
# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).source/etc/network/interfaces.d/*# The loopback network interfaceautoloifaceloinetloopback# The primary network interface#allow-hotplug ens33 # 在源配置前加 # 注释#iface ens33 inet dhcp