GNU/Linux >> Linux の 問題 >  >> Cent OS

ネットワーク インターフェイス リンクのステータスと速度を検出するシェル スクリプト (CentOS/RHEL)

この投稿では、システム上で構成されているインターフェイスを検出するサンプル スクリプトと、それらの中でリンクがアップしているインターフェイスと動作速度を検出するサンプル スクリプトを提供します。仮想マシン内で報告された速度は正しくない可能性があることに注意してください。仮想化されたネットワーク アダプターは、OS が期待する「速度」を装う必要がありますが、それは仮想であるため、仮想 NIC が報告する速度に関係なく、仮想化ホストと物理ネットワークが許可する限り高速に実行されます。

報告される「速度」は、ツール (Linux の ethtool など) が何かを報告できるようにするための単なる数値です。データ転送の実際の速度は制限されません。 VM 上の仮想 NIC によって報告される速度を無視し、速度を仮想化ホストと物理ネットワークに依存するものとして扱います。

スクリプト

1. スクリプトは、稼働中のネットワーク インターフェースとその速度を判断します。
2.仮想インターフェイスは報告されますが、それらの速度は検出されません。
3.スクリプトは結合インターフェースも報告します。

– 以下のスクリプトをサーバーにコピーします:

# 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

– スクリプトに実行権限も付与してください:

# chmod +x detect-speed.sh

サンプル出力

以下は、スクリプトからのサンプル出力です。出力は、ネットワーク インターフェイスの数とそれらのリンク速度によって異なる場合があります。

# ./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


Cent OS
  1. CentOS8またはRHEL8でネットワークサービスを再起動する方法

  2. CentOS / RHEL 7 :ネットワーク インターフェイス名を変更する方法

  3. CentOS/RHEL 7 でネットワーク チーミングを構成する方法

  1. CentOS/RHEL で Docker プロセスと docker0 インターフェイスを無効にする方法

  2. CentOS/RHEL でネットワーク プリンターを削除する方法

  3. CentOS / RHEL :ネットワーク ポートが開いているかどうかを確認する方法は?

  1. CentOS / RHEL 7 :ネットワーク インターフェイス構成ファイルを使用した静的 IP アドレスの構成

  2. CentOS / RHEL 7 で NetworkManager を無効にする方法

  3. CentOS / RHEL 7 :ネットワーク ボンディングまたは NIC チーミングを構成する方法