温馨提示×

linux ifconfig为何找不到

小樊
40
2026-09-20 06:42:06
栏目: 智能运维

现代 Linux 发行版 中,ifconfig 找不到(或提示 command not found不是系统坏了,而是它已经被“淘汰/迁移”了。下面按原因和解决办法说明。


一、为什么 ifconfig 找不到?

1️⃣ ifconfig 属于 net-tools,已被弃用

  • ifconfig 来自老工具包 net-tools
  • 从 2010 年以后,Linux 社区推荐使用 iproute2
  • 很多新系统默认不再安装 net-tools

常见系统:

  • Ubuntu 18.04+
  • CentOS 8 / Rocky / Alma
  • Debian 10+
  • Arch Linux

2️⃣ 系统里根本没装 net-tools

执行:

which ifconfig

输出为空,说明没装。


二、解决办法(三种)

✅ 方法一:安装 ifconfig(不推荐但可用)

# Debian / Ubuntu
sudo apt install net-tools

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

装完即可:

ifconfig

✅ 方法二:使用官方推荐命令 ip(强烈推荐)

ip addr      # 查看 IP(等价于 ifconfig)
ip link      # 查看网卡状态
ip route     # 查看路由

示例:

ip a

✅ 方法三:查看网卡是否启用

ip link show

三、常见误区

❌ 以为 ifconfig 一定存在

新系统默认没有

❌ 用 ifconfig 排查网络问题

官方文档已不推荐使用


四、什么时候还能用 ifconfig?

  • 老服务器(CentOS 6、Ubuntu 14.04)
  • 脚本历史兼容
  • 个人习惯(不推荐)

五、总结一句话

ifconfig 找不到,是因为 Linux 已经用 ip 命令取代了它。

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

  • 你用的是哪个 Linux 发行版
  • 是想查 IP、网卡状态还是配置网络

我可以给你最合适的一条命令。

0