Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 970
avital.ko Avatar asked Dec 02 '25 10:12

avital.ko


1 Answers

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}' 
like image 99
secret squirrel Avatar answered Dec 04 '25 23:12

secret squirrel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!