温馨提示×

为什么linux ifconfig找不到

小樊
65
2026-10-04 23:12:57
栏目: 智能运维

在较新的 Linux 发行版中,ifconfig 命令“找不到”或“命令不存在”,通常不是系统坏了,而是工具被替换或没安装。下面按常见原因给你解释。


一、最常见原因:ifconfig 已逐渐被淘汰

从大约 2010 年以后,很多主流 Linux 发行版(如 Ubuntu、Debian、CentOS 8+、RHEL 8+)默认不再安装 net-tools,而改用 ip 命令。

  • ifconfig 属于 net-tools
  • ip 属于 iproute2(现代标准)

所以你会看到:

bash: ifconfig: command not found

二、怎么确认是不是没装

which ifconfig

如果什么都没输出,就是没装。


三、解决办法

✅ 方法 1:安装 net-tools(不推荐长期使用)

# Ubuntu / Debian
sudo apt install net-tools

# CentOS / RHEL
sudo yum install net-tools
# 或
sudo dnf install net-tools

安装后就能用:

ifconfig

✅ 方法 2(推荐):用 ip 命令代替

查看网卡信息:

ip addr

或简写:

ip a

查看网卡状态:

ip link

启用 / 禁用网卡:

sudo ip link set eth0 up
sudo ip link set eth0 down

四、容器 / 精简系统也很常见

如果你在:

  • Docker 容器
  • Alpine
  • 最小化安装系统

这些环境默认几乎都不带 ifconfig

Alpine 举例:

apk add net-tools

五、快速判断你该用哪个

场景 建议
新系统 / 服务器 用 ip
老脚本 / 老书 装 net-tools
考试 / 老教程 临时装 ifconfig

如果你愿意,可以告诉我:

  • 你用的是 哪个 Linux(Ubuntu?CentOS?)
  • 是 物理机 / 虚拟机 / 容器

我可以直接给你最合适的命令。

0 踩