ifconfig 未显示绑定到机器的所有 IP

pan*_*rma 11 server networking

我在 ubuntu 机器上配置了多个 IP 地址,但是当我运行时ifconfig它只显示其中一个。但是,我能够 ping 分配给这台机器的所有其他地址。

/etc/network/interface 内容:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
     address 192.168.202.11
     netmask 255.255.255.0
     network 192.168.202.0
     broadcast 192.168.202.255
     gateway 192.168.202.1

# dns-* options are implemented by the resolvconf package, if installed   
dns-search idil.dz1.da

auto eth0:1    
iface eth0:1 inet static
     address 192.168.202.12   
     netmask 255.255.255.0

auto eth0:2
iface eth0:2 inet static
     address 192.168.202.13
     netmask 255.255.255.0

auto eth0:3
iface eth0:3 inet static
     address 192.168.202.14
     netmask 255.255.255.0

auto eth0:4
iface eth0:4 inet static
     address 192.168.202.15
     netmask 255.255.255.0

auto eth0:5
iface eth0:5 inet static
     address 192.168.202.16   
     netmask 255.255.255.0
Run Code Online (Sandbox Code Playgroud)

但是, 的输出ifconfig仅为:

192.168.202.11

Rob*_*sak 22

ifconfig基本上已弃用,尽管我知道没有计划摆脱它。替换是ip命令。其现代的等价物ifconfigip address list

为什么ifconfig被替换了ip?在 Linux 网络ifconfig编写之后的几十年里,许多新功能被添加到 Linux 网络中。这涉及一个全新的 API (netlink),供用户空间工具与内核对话以配置网络。编写一个新工具以通过 netlink API 更好地将新功能映射到命令行,比尝试和调整旧ifconfig工具要实际得多。查看ip(8) 联机帮助页,了解您现在可以做的所有很酷的新东西。

该工具使用的内核 APIifconfigifconfig工具本身保持向后兼容性,但该接口对任何不容易映射到旧模型的东西都视而不见。

其原因ifconfig不显示你的IP别名是,它看起来像正在被Debian的加入,他们ifupdown(的包,手柄/etc/network/interfaces)使用不同的机制,它不添加标签:1:2等于是ifconfig工具是盲目的给他们,由于旧 API 强制使用这些标签,因此额外的地址不会映射到旧 API。从ip-address(8) 联机帮助页

          Each address may be tagged with a label string.  In order to
          preserve compatibility with Linux-2.0 net aliases, this string
          must coincide with the name of the device or must be prefixed
          with the device name followed by colon.
Run Code Online (Sandbox Code Playgroud)

maggotbrain 的答案中链接的错误似乎集中在添加支持ifconfig以读取没有标签的地址。另一种方法可能是安排ifupdown创建带有标签的地址,ifconfig以便无需修改即可看到它们。


Kev*_*wen 0

这很可能是 net-tools 包中的错误,ifconfig特别是。

请参阅此处此处的启动板错误以获取更多信息。

如果您手动输入接口,请从命令行使用ifconfig如下命令(遵循上述配置):

sudo ifconfig eth0:1 192.168.202.12 netmask 255.255.255.0
sudo ifconfig eth0:2 192.168.202.13 netmask 255.255.255.0
sudo ifconfig eth0:3 192.168.202.14 netmask 255.255.255.0
sudo ifconfig eth0:4 192.168.202.15 netmask 255.255.255.0
sudo ifconfig eth0:5 192.168.202.16 netmask 255.255.255.0
Run Code Online (Sandbox Code Playgroud)

运行时,您将按预期显示这些界面ifconfig

但是,这些更改不会显示在您的 中/etc/network/interfaces。因此,您需要将它们添加到这两个位置。

注意:这在接口重置后也不会持续存在,因此您需要在重新启动接口/计算机时重新运行命令。