4

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
avital.ko
  • 43
  • 4
  • rather than using `/sys/class/net` and `/proc/net/fib_trie` use `/proc/net/route` since it give you all the information you need. – ebvjr Aug 12 '20 at 15:44
  • If you don't find a good answer here, you might get one from unix.stackexchange.com. – Philip Couling Aug 12 '20 at 16:00
  • for my understanding, `/proc/net/route` shows the routing table, so it gives an IP range for the interface name, but I need the exact IP address that is configured on the interface. Or did I get in wrong? – avital.ko Aug 12 '20 at 16:06
  • I don't have unlocked flags. And I cannot mark as duplicate. Please take a look this:
    https://stackoverflow.com/questions/5281341/get-local-network-interface-addresses-using-only-proc
    – Ivan Onushkin Aug 12 '20 at 16:55

1 Answers1

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}' 
secret squirrel
  • 802
  • 9
  • 13