【Linux】CLI上で使用ネットワーク帯域を確認できるツールiftopの紹介

ネットワークの帯域がどのように使われているか知りたい時があると思います。

その時に便利なのが、CLI上で視覚的に現在使用されている帯域を表示してくれるiftopというツールです。

iftopのインストール方法

Debianなどでは標準のリポジトリにiftopパッケージが用意されています。

aptコマンドなどでinstallするだけです。

# apt install iftop

CentOSなどでは標準リポジトリにiftopパッケージは用意されていないようです。

ですのでEPELリポジトリを利用できるように設定してから、yumコマンドでinstallします。

※epelリポジトリを利用できるようにする
# yum install epel-release

※epelリポジトリのプライオリティを適切(5など)に変更
# vi /etc/yum.repos.d/epel.repo

※iftopパッケージをインストール
# yum install iftop

iftopの使い方

iftopコマンドを起動するだけでネットワーク帯域をグラフィカルに表示してくれます。

※実行ユーザに適切な権限が必要ですので、sudorootユーザで起動するのが楽です。

# iftop
iftop メイン画面

iftop起動後のキー操作は以下のような感じです。

iftop ヘルプ

インターフェースが複数ある場合は対象をiオプションで指定できます。

# iftop -i eth1

nオプションでIPアドレスの逆引きをしないようにできます。

ちなみに起動オプションの簡単な説明は以下のようになっています。

詳しくはman iftopを参照して下さい。

# iftop -h
iftop: display bandwidth usage on an interface by host

Synopsis: iftop -h | [-npblNBP] [-i interface] [-f filter code]
                               [-F net/mask] [-G net6/mask6]

   -h                  display this message
   -n                  don't do hostname lookups
   -N                  don't convert port numbers to services
   -p                  run in promiscuous mode (show traffic between other
                       hosts on the same network segment)
   -b                  don't display a bar graph of traffic
   -B                  Display bandwidth in bytes
   -i interface        listen on named interface
   -f filter code      use filter code to select packets to count
                       (default: none, but only IP packets are counted)
   -F net/mask         show traffic flows in/out of IPv4 network
   -G net6/mask6       show traffic flows in/out of IPv6 network
   -l                  display and count link-local IPv6 traffic (default: off)
   -P                  show ports as well as hosts
   -m limit            sets the upper limit for the bandwidth scale
   -c config file      specifies an alternative configuration file
   -t                  use text interface without ncurses

   Sorting orders:
   -o 2s                Sort by first column (2s traffic average)
   -o 10s               Sort by second column (10s traffic average) [default]
   -o 40s               Sort by third column (40s traffic average)
   -o source            Sort by source address
   -o destination       Sort by destination address

   The following options are only available in combination with -t
   -s num              print one single text output afer num seconds, then quit
   -L num              number of lines to print

iftop, version 1.0pre4
copyright (c) 2002 Paul Warren <pdw@ex-parrot.com> and contributors