插件窝 干货文章 centos重启网卡的方法是什么

centos重启网卡的方法是什么

重启 sudo 网卡 bash 895    来源:    2025-05-01

在 CentOS 中重启网络服务或网卡的方法取决于系统版本(CentOS 7+ 使用 systemd,而 CentOS 6 使用 init)。以下是详细步骤:


1. CentOS 7/8/Stream 及 Rocky Linux/AlmaLinux

方法一:重启整个网络服务(推荐)

sudo systemctl restart network

或(某些版本可能使用 NetworkManager):

sudo systemctl restart NetworkManager

方法二:重启指定网卡(如 eth0ens33

sudo ifdown eth0 && sudo ifup eth0

或使用 nmcli(需安装 NetworkManager):

sudo nmcli connection down eth0 && sudo nmcli connection up eth0

方法三:使用 ip 命令(临时生效)

sudo ip link set eth0 down && sudo ip link set eth0 up

2. CentOS 6

重启网络服务:

sudo service network restart

重启指定网卡:

sudo ifdown eth0 && sudo ifup eth0

3. 通用检查工具

  • 查看网卡状态: bash ip abash ifconfig
  • 检查网络服务状态: bash systemctl status network

注意事项

  1. 网卡名称:根据实际名称替换 eth0(如 ens192enp0s3 等,可通过 ip a 查看)。
  2. NetworkManager:如果系统使用 NetworkManager,优先使用 nmclinmtui 工具。
  3. 持久生效:修改配置文件(/etc/sysconfig/network-scripts/ifcfg-eth0)后需重启服务。

常见问题

  • 失败提示:若报错 Device eth0 does not exist,确认网卡名称是否正确。
  • 防火墙:重启后检查防火墙是否阻止连接(sudo systemctl restart firewalld)。

如有其他问题,请提供具体错误信息以便进一步排查!