centos8重启网络服务

CentOS 7中支持network.service和NetworkManager.service 2种方式配置网络,而在CentOS 8中已经废弃network.service,需要通过NetworkManager.service配置网络。因此通过systemctl restart network已经无法使用了。
————————————————

[root@nas ~]# cat /etc/redhat-release 
CentOS Linux release 8.5.2111
[root@nas ~]# systemctl restart network
Failed to restart network.service: Unit network.service not found.

  • 方法一
    使用nmcli命令,需要两条指令,重启网卡之前需要重新载入配置文件,不然不能立即生效
[root@nas ~]# nmcli connection show
NAME UUID TYPE DEVICE
enp3s0     11a52fb6-6295-476f-b5ee-702884631006 ethernet enp3s0
emhy       37df473c-625f-47fc-b3ce-d4d6842233bb wifi     wlp2s0
docker0    9f1ea515-c499-4d18-a8a6-85a612411496 bridge   docker0
virbr0     ddd7ec7d-57b1-450c-9581-641c148d01fb bridge   virbr0


[root@nas ~]# nmcli c reload
[root@nas ~]# nmcli d connect enp3s0
成功用 "enp3s011a52fb6-6295-476f-b5ee-702884631006" 激活了设备 ""。

  • 方法二
    使用ifdown和ifup
[root@nas ~]# ifdown enp3s0;ifup enp3s0 
Connection 'enp3s0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)

参考:CentOS8 网卡命令使用|CentOS8 重启网卡方法

⚑Tags: