• 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. Detect rootkits & malware on Linux Servers using rkhunter
  2. How to Extend allowed number of loopback devices
  3. Firewalld Command line Reference (Cheat Sheet)
  4. How to use the ssh-keygen Command in Linux
  5. CentOS / RHEL 7 : How to check the status of a service using systemd
  6. What is the difference between & (ampersand) and && (double ampersand) while executing simultaneous commands on Linux
  7. RCRON – Setup High Availability of cron Jobs
  8. How to Find Number of CPU Sockets on a CentOS/RHEL System
  9. route Command Examples in Linux
  10. “passwd: Module is unknown” – error while changing the password in CentOS/RHEL 6

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright