Bash Get Name of Ethernet Network Interface

Posted on November 3, 2020 at 8:17 pm

Here is a bash command to get name of ethernet network interface:

ip link | awk -F: '$0 !~ "lo|tun|vir|wg|wl|^[^0-9]"{print $2;getline}' | awk '{$1=$1};1'

It will exclude lo (local), tun0 (openvpn), wg0 (wireguard), wl* (wireless), etc.

If you have multiple ethernet network interface and want to get first one:

ip link | awk -F: '$0 !~ "lo|tun|vir|wg|wl|^[^0-9]"{print $2;getline}' | head -1 | awk '{$1=$1};1

Another way is to use this command:

ls /sys/class/net | grep ^e

Receive updates via email

Other Posts

Updated Posts