This post provides a sample script detecting which interfaces are configured on the system, and in them, which ones do have their links up and at which speed they are operating. Note, that the reported speed within virtual machines may not be correct. A virtualized network adapter has to pretend to have a “speed” because the OS expects it, but because it’s virtual, it will run as fast as the virtualization host and physical network allow, irrespective of the speed the virtual NIC reports.
The reported “speed” is just a number to make tools (e.g. ethtool on Linux) able to report something; it doesn’t limit the actual speed of data transfer. Ignore the speed reported by the virtual NIC on the VM and treat the speed as depending on the virtualization host and physical network.
The Script
1. The script will determine which network interfaces are up and their speed.
2. It will report the virtual interfaces but does not detect any speed for them.
3. The script will report bond interfaces as well.
– Copy the below script onto your server:
# vim detect-speed.sh #!/bin/bash for net_dev in `find /sys/class/net/ -type l`; do # only need filename without path net=`basename $net_dev` speed=`ethtool $net | grep Speed | cut -d ':' -f 2 | tr -d " "` link=`ethtool $net | grep "Link detected" | cut -d ':' -f 2 | tr -d " "` # print result if [[ "$link" != "yes" ]]; then echo "interface $net has no link detected" else if [[ "$speed" == "" ]]; then echo "interface $net has link detected but no speed (virtual ?)" else echo "interface $net has link detected with speed $speed" fi fi done
– Make sure you also provide executible permission to the script:
# chmod +x detect-speed.sh
Sample output
Below is a sample output from the script. Your output may differ according to the number of network interfaces and their link speeds.
# ./detect-speed.sh interface vif3.0 has link detected but no speed (virtual ?) interface vif10.0 has link detected but no speed (virtual ?) interface 0aacd800 has link detected but no speed (virtual ?) interface p2p1.2 has link detected with speed 1000Mb/s interface bond0 has link detected with speed 1000Mb/s interface p2p1 has link detected with speed 1000Mb/s interface p4p1 has link detected with speed 1000Mb/s interface lo has link detected but no speed (virtual ?) interface em1 has link detected with speed 1000Mb/s