在 Linux 中,ifconfig 本身不能重启网络,它只能查看和配置网络接口。要“重启网络”,通常有以下几种方式(取决于发行版和版本):
如果你只是想重启某个网卡(如 eth0):
sudo ifconfig eth0 down
sudo ifconfig eth0 up
或等价写法:
sudo ifdown eth0
sudo ifup eth0
⚠️
ifdown / ifup依赖/etc/network/interfaces(Debian 系)
sudo /etc/init.d/networking restart
或
sudo service networking restart
sudo systemctl restart networking
如果是 Netplan(Ubuntu 18.04+):
sudo netplan apply
service network restart
systemctl restart network
或针对某个网卡:
nmcli connection down eth0
nmcli connection up eth0
sudo reboot
ifconfig -a
或
ip addr
如果你能告诉我:
我可以给你最准确的一条命令 ✅