How can I find active network interface from userland?
8,303
Something like this?
ip addr | awk '/state UP/ {print $2}'
enp0s3:
This command was issued as a "regular" (non-root
) user on:
uname -a
Linux centos 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
If it is important to remove the trailing :
from the interface name, use (for example):
ip addr | awk '/state UP/ {print $2}' | sed 's/.$//'
enp0s3
Related videos on Youtube
Author by
iago-lito
'considering leaving https://writing.meta.stackexchange.com/questions/2301/sadly-it-is-time-for-me-to-join-the-exodus
Updated on September 18, 2022Comments
-
iago-lito over 1 year
I know that I can find which network interface is currently being used by parsing the output of:
# ifconfig
or
# route
But how can I get this information as a non-root user? Is there a way I can build such a
$ magic-command
whose ouput would be
none
lo
orwlan0
oreth0
depending on the device used.. or evenenp3s0f1
orwlp2s0
on exotic systems, with no admin rights? -
iago-lito about 7 yearsPerfect, cheers :)
-
MaXi32 almost 3 yearsDoes this work in a virtual machine with bridged connection ? Tried this doesn't work.. it doesn't have the text state UP