本文主要是介绍Linux shell 列举当前所有网卡的IPV4地址及网卡名。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
命令一:
ip -4 addr show | grep inet | awk '{ printf "%s ", $2; for (i=5; i<=NF; i++) { printf "%s ", $i }; printf "\n" }' | awk '{print $1, $NF}'
命令二:
忽略 lo 环路网卡
ip -4 addr show | grep inet | awk '{ printf "%s ", $2; for (i=5; i<=NF; i++) { printf "%s ", $i }; printf "\n" }' | awk '{print $1, $NF}' | grep -v "lo"
命令三:
只枚举物理网卡名:
lshw -class network | grep "name:" | awk '{print $3}'
命令四:
只枚举物理网卡名+IP地址:
lshw -class network | grep "name:" | awk '{print $3}' | while read interface; do ip -4 addr show | grep inet | awk -v interface="$interface" '$NF == interface {print $2, $NF}'; done
这篇关于Linux shell 列举当前所有网卡的IPV4地址及网卡名。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!