D.W. D.W. - 1 year ago 109
Linux Question

Get interface name into linux shell script variable

I would like to store an interface name into a variable in linux shell script. I found a solution to do this via "grep" command and the IP-Address. My problem is that my interface doesn't have an IP-Address at this moment.

The interface name always begins with "enx" and the MAC-Address like "enxb2240be99fc3" while the MAC-Address can change every reboot.

Is there a solution to get this interface name into a shell script variable?

Answer Source
iname=$(ip -o link show | sed -rn '/^[0-9]+: en/{s/.: ([^:]*):.*/\1/p}')

save the interface name to variable iname

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download