ifconfig 查不到网卡,通常不是网卡不存在,而是命令本身或系统环境发生了变化。下面按常见原因给你排查思路(Linux 为主,顺带 macOS)。
ifconfig 已被弃用 / 未安装ifconfig很多现代 Linux 默认不再安装 net-tools:
✅ 验证:
ifconfig
如果提示:
command not found
说明 ifconfig 不存在,不是网卡问题。
✅ 解决方案(任选):
ip addr
ip link
这是推荐替代命令。
eth0现代 Linux 使用 可预测网卡命名:
ens33enp0s3enp2s0wlp3s0(无线)✅ 查看所有网卡:
ip link
✅ 只看网卡名:
ls /sys/class/net/
ifconfig 默认只显示 UP 状态网卡。
✅ 查看所有网卡(包括 down):
ip link
✅ 启用网卡(示例):
sudo ip link set eth0 up
✅ 检查是否存在网卡:
lspci | grep -i net
✅ 检查驱动是否加载:
lsmod | grep -i driver_name
✅ 查看内核日志:
dmesg | grep -i eth
ifconfig✅ 容器内推荐:
ip addr
✅ 如果是容器,这是正常现象。
macOS 默认网卡名是:
en0en1✅ 查看:
ifconfig
如果没装 Xcode Command Line Tools,也可能提示找不到命令。
# 1. 是否真的没有 ifconfig
which ifconfig
# 2. 查看所有网卡
ip link
# 3. 看是否有网卡但没 UP
ip addr
# 4. 是不是在容器里
cat /proc/1/cgroup
不是网卡没了,而是
ifconfig已过时或网卡未启用。
如果你愿意,可以把下面信息发我,我可以精准判断:
ip addr 的输出