注:本文基于CentOS 8.3编写
CentOS 7中支持network.service和NetworkManager.service 2种方式配置网络,而在CentOS 8中已经废弃network.service,需要通过NetworkManager.service配置网络。因此通过systemctl restart network已经无法使用了。
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 8.3.2011 [root@localhost ~]# systemctl restart network Failed to restart network.service: Unit network.service not found.
方法一:
使用nmcli命令,需要两条指令,先加载配置,然后应用
[root@localhost ~]# nmcli c reload [root@localhost ~]# nmcli c up ens33 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
方法二:
使用ifdown和ifup
[root@localhost ~]# ifdown ens33;ifup ens33 Connection 'ens33' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9) Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)