简体   繁体   中英

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?

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.

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.

Try this:

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

Using the ip system utility. You're not using /proc/ or /sys/, but it'll work on any distro with ip on it, which is most of them.

Update: to make it look a bit easier on the eye, use this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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