在 Linux 中执行 ifconfig 报错,通常有下面几类原因,你可以对照看看是哪一种:
ifconfig 命令不存在(最常见)bash: ifconfig: command not found
ifconfig 属于 net-tools 包,而新系统推荐使用 ip 命令方法 1:安装 net-tools
# Ubuntu / Debian
sudo apt install net-tools
# CentOS / RHEL
sudo yum install net-tools
# 或
sudo dnf install net-tools
方法 2(推荐):使用 ip 命令
ip addr
ip link
ip route
Permission denied
sudo ifconfig
ifcofig、ifconfg检查:
which ifconfig
echo $PATH
这些环境通常:
ifconfigip解决:
# 容器里
apt update && apt install net-tools
# 或
yum install net-tools
✅ 不要再依赖 ifconfig
ip a
ip -br addr
如果你愿意,可以把具体报错信息或系统版本贴出来(如 cat /etc/os-release),我可以更精准地帮你判断。