简体   繁体   English

如何在 Linux 上使用 /proc 获取所有 IP 接口名称和地址?

[英]How to get all the IP Interface names and addresses using /proc on Linux?

I know of ls /sys/class/net to get all the available IP interface names, and also cat /proc/net/fib_trie to get all the IP addresses, but how do I match between them?我知道ls /sys/class/net可以获取所有可用的 IP 接口名称,还知道cat /proc/net/fib_trie可以获取所有 IP 地址,但我该如何匹配它们?

My desired result is a list of IP interface names and the IP address assigned to every interface name, similar to the info showed by ifconfig but that can be applied on any Linux distribution.我想要的结果是 IP 接口名称列表和分配给每个接口名称的 IP 地址,类似于ifconfig显示的信息,但可以应用于任何 ZEDC9F0A5A5D57797BF68E3736474383Z 分布。

for example:例如:

enp4s0f1  5.6.7.1
enp6s0    2.2.2.1

My desired result is a list of IP interface names and the IP address assigned to every interface name, similar to the info showed by ifconfig but that can be applied on any Linux distribution.我想要的结果是 IP 接口名称列表和分配给每个接口名称的 IP 地址,类似于 ifconfig 显示的信息,但可以应用于任何 ZEDC9F0A5A5D57797BF68E3736474383Z 分布。

Try this:尝试这个:

ip addr | grep inet | grep -v "inet6"

Using the ip system utility.使用ip系统实用程序。 You're not using /proc/ or /sys/, but it'll work on any distro with ip on it, which is most of them.您没有使用 /proc/ 或 /sys/,但它可以在任何带有 ip 的发行版上运行,这是大多数发行版。

Update: to make it look a bit easier on the eye, use this:更新:为了让它看起来更容易,使用这个:

ip addr | grep inet | grep -v "inet6" | awk '{print $2 " " $8}' 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM