在 Linux 中出现 ifconfig: command not found 或 ifconfig 报错,通常有以下几种原因和对应解决办法:
ifconfig 命令不存在(最常见)新版本 Linux(如 CentOS 7+、Ubuntu 18.04+)默认 不再安装 net-tools,而 ifconfig 属于 net-tools。
sudo yum install net-tools
或
sudo dnf install net-tools
sudo apt update
sudo apt install net-tools
安装完成后即可使用:
ifconfig
Permission denied
使用 root 或 sudo:
sudo ifconfig
可能原因:
ifconfig -a
sudo ifconfig ens33 up
ip 命令(现代方式)ifconfig 已逐渐被弃用,建议使用:
ip addr # 查看 IP
ip link # 查看网卡状态
ip route # 查看路由
which ifconfig
# 若为空,说明未安装
sudo apt install net-tools # Ubuntu
sudo yum install net-tools # CentOS
ifconfig -a
如果你能提供 具体的报错信息(比如完整错误提示、Linux 发行版),我可以更精准地帮你解决。