• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Shell Script to Find Network Interface Link Status and Speed (CentOS/RHEL)

by admin

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

Filed Under: CentOS/RHEL, Linux

Some more articles you might also be interested in …

  1. How to check change log of RPM packages on CentOS/RHEL
  2. CentOS / RHEL 7 : How to disable IPv6 on a specific interface only
  3. gnome-terminal Command Examples in Linux
  4. Common NFS mount options in Linux
  5. cargo rustc: Compile a Rust package, and pass extra options to the compiler
  6. namei: command not found
  7. efibootmgr: command not found
  8. Passwordless SSH not working for local users on LDAP servers – CentOS/RHEL 7
  9. pw-loopback Command Examples in Linux
  10. How to Disable the ‘lvm2-lvmetad.socket/service’ on CentOS/RHEL 7

You May Also Like

Primary Sidebar

Recent Posts

  • cf: Command-line tool to manage apps and services on Cloud Foundry
  • certutil: Manage keys and certificates in both NSS databases and other NSS tokens
  • cdk: A CLI for AWS Cloud Development Kit (CDK)
  • cd: Change the current working directory

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright