在Linux中,网络管理器的选择对于系统性能和网络设置有很大的影响,NetworkManager是一个非常流行的网络管理工具,而systemd-network是Linux内核的一部分,它提供了更加稳定和高效的网络管理功能,本文将介绍如何在Linux中将网络管理器由NetworkManager切换为systemd-network。
NetworkManager简介
NetworkManager是一个通用的网络管理工具,可以自动配置和管理网络连接,它支持多种协议,如DHCP、DNS、代理等,并允许用户通过图形界面或命令行进行配置,NetworkManager的主要优点是易于使用和扩展性好,但它也存在一些缺点,如性能较差、配置复杂等。
systemd-network简介
systemd-network是Linux内核的一部分,它提供了一种简单的方式来配置和管理网络连接,通过使用systemd-network,用户可以在不修改网络接口配置文件的情况下更改网络设置,systemd-network还支持动态IP地址分配、DNS解析等功能,使得网络管理变得更加简单和高效。
如何将NetworkManager切换为systemd-network
1、安装systemd-network
需要在系统中安装systemd-network,在基于Debian的系统(如Ubuntu)中,可以使用以下命令安装:
sudo apt-get install systemd-networkd
在基于RHEL的系统(如CentOS)中,可以使用以下命令安装:
sudo yum install systemd-networkd
2、禁用NetworkManager
接下来,需要禁用NetworkManager,可以通过编辑NetworkManager的配置文件来实现这一点,在大多数系统中,该文件位于/etc/NetworkManager/NetworkManager.conf
,使用文本编辑器打开该文件,并找到以下行:
[main] dns=dnsmasq
将其注释掉,如下所示:
; [main] ; dns=dnsmasq
重启NetworkManager服务以应用更改:
sudo systemctl restart NetworkManager
3、启用systemd-network
现在,已经成功禁用了NetworkManager,可以启用systemd-network了,同样地,在大多数系统中,该服务位于/etc/systemd/system/multi-user.target.wants/network-manager.service
,使用文本编辑器打开该文件,并确保其中的内容如下所示:
[Unit] Description=Network Manager for systemd-based systems After=network.target network-online.target Documentation=man:systemd-networkd(8) DocumentationUrl=http://www.freedesktop.org/wiki/Software/systemd/networking/index.html BindsTo=network-online.target network-dhcp6.target firewalld.service avahi-daemon.service nscd.service udevadm.service dbus-daemon.service gpm.service polkitd.service bluetooth.service iwd.service wpa_supplicant.service systemd-resolved.service systemd-timesyncd.service systemd-tmpfiles-setup.service systemd-random-seed-directory.service systemd-random-seed.service acpid.service rsyslog.service timesyncd.service libnss-myhostname.so systemd-hostnamed.service systemd-logind.service systemd-udev-trigger.service systemd-user@socket service sshd.service sulogin.service apparmor.service auditd.service cronie.service cups-pdf.service postfix.service setroubleshoot.service syslogrotate.service xdmcp.service xsltproc.timer zfsdumpcodezfsquota zfsquota nfs-common nfslock krb5ccpreauth nscd avahi-autoipd e2fsck e2fsck.noatime ext4-resize fstrim resolvconf rpcbind rpcidmapped rtkit rtmpdump screen udevd udevrun unattended-upgrades update-notifier vboxadd vboxnetadp vboxpciutils wpa_supplicant watchdog -Requires=network-online.target network-dhcp6.target firewalld.service avahi-daemon.service nscd.service udevadm.service dbus-daemon.service gpm.service polkitd bluetooth iwd wpa_supplicant systemd-resolved systemd-timesyncd systemd-tmpfiles-setup systemd-random-seed systemd-random-seed-directory acpid rsyslog timesyncd libnss-myhostname systemd-hostnamed systemd-logind systemd-udev-trigger systemd-user@socket sshd sulogin apparmor auditd cups-pdf postfix setroubleshoot syslogrotate xdmcp xsltproc zfsdumpcodezfsquota zfsquota nfs-common nfslock krb5ccpreauth nscd avahi-autoipd e2fsck e2fsck.noatime ext4-resize fstrim resolvconf rpcbind rpcidmapped rtkit rtmpdump screen udevd udevrun unattended-upgrades update-notifier vboxadd vboxnetadp vboxpciutils wpa_supplicant watchdog -After=multi-user.target network-online.target
保存并关闭文件后,重新加载systemd守护进程以应用更改:
sudo systemctl daemon-reload
4、启动并启用systemd-network服务
启动并启用systemd-network服务,在大多数系统中,可以使用以下命令:
sudo systemctl enable --now network || sudo systemctl enable network && sudo systemctl start network
至此,已经成功将网络管理器从NetworkManager切换为systemd-network,可以使用以下命令检查当前正在运行的服务:
ps aux | grep 'systemctl is running' || ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' && ps aux | grep 'systemctl is running' || sudo service systemd-network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network start || sudo service network
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/219470.html