在 Linux 中,ifconfig 本身不能重启网络,它只是用来查看和配置网络接口。如果你想“通过 ifconfig 重启网络”,通常是指先 down 再 up 某个网卡。
sudo ifconfig eth0 down
sudo ifconfig eth0 up
或(等价写法):
sudo ifdown eth0
sudo ifup eth0
把
eth0换成你的网卡名(如ens33、enp0s3)
查看网卡名:
ifconfig -a
service network restart
systemctl restart NetworkManager
或
nmcli networking off
nmcli networking on
/etc/init.d/networking restart
sudo netplan apply
现在更推荐用 ip 命令代替 ifconfig:
sudo ip link set eth0 down
sudo ip link set eth0 up
down 网卡,会断 SSHnetplan / NetworkManagerifconfig 在新系统中可能默认没装(需 apt install net-tools)如果你告诉我 具体系统(CentOS/Ubuntu?版本?),我可以给你最准确的一条命令。