在 Debian 里 ifconfig 不显示网卡,通常不是系统没网卡,而是 命令本身或环境的问题。下面按最常见原因给你排查。
ifconfig 已不再默认安装从 Debian 9(Stretch)开始,ifconfig 属于 net-tools 包,而 Debian 默认不再安装它。
which ifconfig
如果没有输出,说明没装。
sudo apt update
sudo apt install net-tools
安装后再试:
ifconfig
如果你看到类似这样:
lo: flags=...
但 没有 eth0 / ens33 / wlan0,常见原因有:
ip link
如果看到网卡是 DOWN:
2: ens33: <BROADCAST,MULTICAST> mtu 1500 qdisc ... state DOWN
启用它:
sudo ip link set ens33 up
ifconfig 默认只显示已启用且有 IP 的接口。
用以下命令查看所有接口(包括未启用的):
ip addr
或
ifconfig -a
ip 命令(替代 ifconfig)ifconfig 已过时,Debian 官方推荐:
ip addr # 查看所有网卡和 IP
ip link # 查看网卡状态
ip route # 查看路由
示例:
ip addr show
systemctl status NetworkManager
如果没运行:
sudo systemctl enable NetworkManager
sudo systemctl start NetworkManager
编辑:
sudo nano /etc/network/interfaces
示例(DHCP):
auto eth0
iface eth0 inet dhcp
然后:
sudo systemctl restart networking
| 问题 | 解决 |
|---|---|
| 网卡是 NAT 但没显示 | 确认虚拟机设置中网卡已启用 |
| 是 ens33 / enp0s3 | 这是正常的,不是 eth0 |
| 只显示 lo | 没加载网卡驱动 |
查看网卡:
ip addr
✅ 先执行:
ip addr
net-tools如果你愿意,可以把下面命令的输出贴出来,我可以直接帮你判断是哪一类问题:
ip addr
ip link
lsb_release -a