I am working on a shell script which needs to know the logical name (eth0, eth1, etc) associated with a given ip. The current procedure I am employing is to parse the output of ifconfig using filters and getting the NIC card associated with a given IP. I was wondering if there exists a simpler way or a direct pipelined linux command to get the above mentioned detail?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Take this:
#!/bin/sh
ip=192.168.1.10
iface=$(ip addr | grep $ip | awk '{print $NF}')
echo "Iface is: ${iface}"