ifconfig 在 Linux 上“失效”通常不是命令本身坏了,而是环境或系统变化导致的。常见原因和对应解决办法如下:
现代很多 Linux 发行版默认不再安装 net-tools(ifconfig 属于这个包)。
bash: ifconfig: command not found
sudo apt install net-tools
sudo yum install net-tools
sudo pacman -S net-tools
即使安装了,也可能不在 PATH。
which ifconfig
ls /sbin/ifconfig
export PATH=$PATH:/sbin
或修改 .bashrc 永久生效。
ifconfig 已被官方标记为过时工具。
ip addr
ip link
ip route
例如:
ip a # 查看 IP
ip r # 查看路由
在:
中,ifconfig 可能看不到预期网卡。
ip netns
某些系统下需要 root 才能运行完整功能。
sudo ifconfig
如路由器、IoT 设备:
ifconfigip 或 busybox ifconfigifconfig 没坏,只是 Linux 已经“不推荐用它了”
如果你愿意,可以告诉我:
我可以更精准帮你定位。