在 Linux 中执行 ifconfig 后“无网络”,通常不是 ifconfig 本身的问题,而是网络接口没有正确配置或启用。下面按常见原因给你梳理一下。
请先区分是哪一种:
ifconfig 命令不存在ifconfig 有输出,但没有 inet 地址(无 IP)ping 不通外网eth0、ens33)net-tools(ifconfig 不存在)新版本 Linux(CentOS 8 / Ubuntu 20+)默认没有 ifconfig
command not found: ifconfig
✅ 解决:
# Ubuntu / Debian
sudo apt install net-tools
# CentOS / RHEL
sudo yum install net-tools
或直接使用新命令:
ip addr
ifconfig 看到网卡但没 inet
示例:
eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
✅ 解决:
sudo ifconfig eth0 up
# 或
sudo ip link set eth0 up
常见于虚拟机或新装系统
sudo dhclient eth0
或(Ubuntu):
sudo netplan apply
检查配置文件:
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/netplan/*.yaml
常见错误:
BOOTPROTO=none 但没写 IP如果你在 VMware / VirtualBox:
✅ 解决:
即使有 IP,也可能被挡
# 临时关闭防火墙测试
systemctl stop firewalld
# 或
ufw disable
ping 8.8.8.8 # 通
ping www.baidu.com # 不通
✅ 解决:
/etc/resolv.conf
nameserver 8.8.8.8
ip addr
ip route
ping 8.8.8.8
ping www.baidu.com
你可以把下面信息发我,我可以直接帮你定位:
ifconfig 或 ip addr 的输出我可以一步一步帮你把网络调通。