温馨提示×

linux ifconfig怎么重启网络

小樊
43
2026-09-20 06:44:04
栏目: 智能运维

在 Linux 中,ifconfig 本身不能重启网络,它只是用来查看和配置网络接口。如果你想“通过 ifconfig 重启网络”,通常是指先 down 再 up 某个网卡

一、用 ifconfig 重启某个网卡(最常见)

sudo ifconfig eth0 down
sudo ifconfig eth0 up

或(等价写法):

sudo ifdown eth0
sudo ifup eth0

eth0 换成你的网卡名(如 ens33enp0s3

查看网卡名:

ifconfig -a

二、重启整个网络服务(取决于发行版)

1. CentOS / RHEL 6 及以前

service network restart

2. CentOS / RHEL 7+(systemd)

systemctl restart NetworkManager

nmcli networking off
nmcli networking on

3. Ubuntu / Debian(老版本)

/etc/init.d/networking restart

4. Ubuntu 18.04+(Netplan)

sudo netplan apply

三、推荐做法(现代 Linux)

现在更推荐用 ip 命令代替 ifconfig

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

四、常见坑

  • 远程服务器不要随便 down 网卡,会断 SSH
  • 云服务器建议用控制台或 netplan / NetworkManager
  • ifconfig 在新系统中可能默认没装(需 apt install net-tools

如果你告诉我 具体系统(CentOS/Ubuntu?版本?),我可以给你最准确的一条命令。

0