How to get the logical name of the NIC card based on the associated ip address?

I am working on a shell script that needs to know the logical name (eth0, eth1, etc.) associated with this ip. The current procedure I'm using is to analyze ifconfig output using filters and get the NIC map associated with this IP. I was wondering if there is an easier way or direct linux pipelining command to get the above details?

+4
source share
1 answer

Take this:

#!/bin/sh ip=192.168.1.10 iface=$(ip addr | grep $ip | awk '{print $NF}') echo "Iface is: ${iface}" 
+4
source

Source: https://habr.com/ru/post/1489778/


All Articles