在 Linux 中执行 ifconfig 出现“错误”或“命令未找到”,通常由以下几种常见原因导致。你可以对照看看属于哪一种。
ifconfig: command not found(最常见)在新版 Linux 发行版(如 CentOS 7+/8、Ubuntu 18.04+)中:
ifconfig 属于 net-tools 包# CentOS / RHEL
yum install -y net-tools
# 或
dnf install -y net-tools
# Ubuntu / Debian
apt install -y net-tools
安装后:
ifconfig
Permission deniedifconfig 需要 root 权限
sudo ifconfig
或切换为 root:
su -
ifconfig
ifconfig 能运行但看不到网卡ip 命令体系(推荐)ip addr
ip link
启用网卡示例:
ip link set eth0 up
现代 Linux 更推荐使用 iproute2:
| 旧命令 | 新命令 |
|---|---|
| ifconfig | ip addr |
| route | ip route |
| arp | ip neigh |
示例:
ip addr show
ip route show
解决:
apt/yum install net-tools
which ifconfig
echo $PATH
sudo -i
ip addr
如果你能贴出具体的报错信息(截图或文字),我可以更精确地告诉你原因和修复方法。