我应该停止使用 Ifconfig 吗?

Zhe*_*hen 185 networking linux ifconfig iproute2

对于挂载 Infiniband 卡的服务器,当我使用该ifconfig命令时,我收到以下警告:

Ifconfig uses the ioctl access method to get the full address 
information, which limits hardware addresses to 8 bytes.
Because Infiniband address has 20 bytes, only the first 8 bytes 
are displayed correctly.
Ifconfig is obsolete! For replacement check ip.
Run Code Online (Sandbox Code Playgroud)

我应该停止使用ifconfig吗?它是否已被弃用以支持该ip命令?还是会在近期更新?

注意:这个问题和答案是关于GNU/Linux 的“主要”发行版的。不应假定该信息适用于所有发行版,尤其不适用于其他操作系统。

小智 166

引用Thomas Pircher的网站(cc-by-sa):

ifconfig vs ip

该命令/bin/ip已经存在一段时间了。但是人们继续使用旧的命令/sbin/ifconfig。让我们明确一点:ifconfig不会很快消失,但它的新版本ip更强大,最终将取代它。

的手册页一开始ip可能看起来很吓人,但是一旦您熟悉了命令语法,就会很容易阅读。本页不会介绍ip的新特性。它具有并排比较 ififconfigip命令语法的快速概览。

显示网络设备和配置

ifconfig

ip addr show
ip link show
Run Code Online (Sandbox Code Playgroud)

启用网络接口

ifconfig eth0 up
ip link set eth0 up
Run Code Online (Sandbox Code Playgroud)

以类似的方式禁用网络接口:

ifconfig eth0 down
ip link set eth0 down
Run Code Online (Sandbox Code Playgroud)

  • 有趣的是,在您提到的每个用例中,ip 命令都变得更长更复杂。可能是人们仍然使用 `ifconfig` 的主要原因 (56认同)
  • @TheLQ:`ip` 提供了很多很多功能。当然,它更复杂。无论如何,许多命令都可以缩短。例如,`ip addr show` 可以简写为`ip a`,`ip link show` 简写为`ip l`,`ip link set eth0 up` 简写为`ip l set eth0 up` 等等。这使 `ip` 与 `ifconfig` 相提并论。 (23认同)
  • 请记住,整个世界都不是 Linux 机器。Solaris、AIX、HP-UX、所有的 BSD 和 SCO(没有人关心*他们*)都使用 `ifconfig`。如果你想成为一个 *unix* 管理员(不仅仅是 *Linux* 管理员),你应该确保你至少熟悉 ifconfig 及其基本语法...... (19认同)
  • 你的第一个例子回答了它。为什么在执行 1 个命令时运行 2 个命令? (10认同)
  • @ott `ip addr show` 几乎包含了 `ip link show` 的输出。 (6认同)
  • `ip addr show` 可以缩写为 `ip a`,你肯定会喜欢 ifconfig 输出的外观。但是 ifconfig 的输出并不总是列出所有的 IP 地址。在我的书中,这很糟糕。 (2认同)

Tot*_*tor 47

是的,在 Linux 上ifconfig不推荐使用 iproute2(ip命令)。

同样,arp,routenetstat命令也已弃用。

但是, iproute2 是 Linux 特定的,当其他一些 Unix 使用时ifconfig,因此如果您打算使用另一个 Unix,了解/记住它是如何工作的可能会有所帮助...

要学习“新方法”,我建议您查看这 3 个链接:

根据最后一个链接,ifconfig已经+15年没有维护了

除了 Debian 积累的大量补丁外,net-tools 软件包在 2001 年 4 月 15 日左右发布的 1.60 版本之后没有看到任何上游开发。

  • `ifconfig` 是由 BSD 开发的。Linux 本质上使用了 BSD 的 IP 堆栈(就像当时的 Windows 和其他人一样,为什么 `ipconfig` 仍然类似于 `ifconfig`)。在 2.4 Kernel Linux 开始与 BSD 的堆栈发生严重分歧时,那是 2001 年初。Linux 中的 `ifconfig` 从那时起没有得到很好的维护并不是偶然的。 (9认同)
  • 10年!?我想是时候在 GitHub 上启动“save ifconfig”项目了。 (4认同)

Sve*_*ven 20

ifconfig 现已弃用多年,是时候切换了,尤其是在像您这样的情况下。

  • 我从未听说过“ip”。我刚刚在 FreeBSD 服务器上对其进行了测试,它显示“ip: Command not found.”。也许 `ifconfig` 只在 Linux 上被弃用。 (10认同)
  • 嗯。有足够多的脚本和其他工具是基于 ifconfig 构建的,我觉得在它消失之前不需要切换...... (5认同)
  • @ctype.h:确实,它只在 linux 上被弃用。ifconfig 针对 linux 的发布可以追溯到 1999 年。`ip` 已经是 2.4 内核的推荐选择。 (2认同)

Fla*_*ash 5

ip已经有ifconfig一段时间的替代品,可能在某个时候ifconfig会更新,但是我不会等待它并学习使用ip它。它支持所有 linux 发行版

  • ip 已经替代了 ifconfig ** on Linux**,作为一些发行版的选择。 (8认同)