Skip to content

Instantly share code, notes, and snippets.

@consolewitch
Last active April 3, 2018 17:26
Show Gist options
  • Save consolewitch/da1d89f8cfcfd58ad365e6ea98461f16 to your computer and use it in GitHub Desktop.
Save consolewitch/da1d89f8cfcfd58ad365e6ea98461f16 to your computer and use it in GitHub Desktop.
get_eth_device_from_adapter_number.sh
#! /bin/bash
###
# Written by Alex N. Speaks
# Takes the position in which a NIC appears in the vmware console as an argument.
# Returns the ethernet device name that corresponds to that position number.
# Position numbers start at 0
# You can think of this as the old-style ethX number
NIC_INDEX=$1
FOUND=1
for dir in /sys/bus/pci/devices/*/
do
if [ -f $dir/label ] && \
[ $(cat ${dir}/label|tr -d '\n') == "Ethernet${NIC_INDEX}" ] && \
[ -d $dir/net/ ]
then
ls $dir/net/
FOUND=0
fi
done
exit ${FOUND}
@consolewitch
Copy link
Author

I found the information to create this script here:
https://communities.vmware.com/message/2739082#2739082

I didn't want to do any weird renaming or disable the new ethernet device naming scheme because of the warnings found in this article: https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment