在 Debian(尤其是较新版本,如 Debian 9 及以后)中,ifconfig 报错通常是因为 net-tools 未安装 或 命令路径问题。下面分情况说明解决办法。
bash: ifconfig: command not found这是最常见的情况。
原因:
net-toolsifconfig 属于 net-tools 包sudo apt update
sudo apt install net-tools
安装完成后即可使用:
ifconfig
Debian 官方推荐使用 ip 命令替代 ifconfig:
ip addr # 查看 IP 地址
ip link # 查看网卡状态
ip route # 查看路由
示例:
ip a
即使装了 net-tools,普通用户也可能无法执行:
sudo ifconfig
如果你在:
通常默认没有 ifconfig,必须手动安装 net-tools。
which ifconfig
输出类似:
/usr/sbin/ifconfig
如果没有输出,说明没装或不在 PATH。
✅ 最快解决:
sudo apt install net-tools
✅ 更现代、推荐:
ip addr
如果你愿意,可以把具体报错信息贴出来,我可以更精准帮你分析。