Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 安裝 iftop 實時流量監控工具完整教程

編輯:Linux 教學

iftop 是類似 top 的網絡流量實時監控工具,能顯示網卡當前帶寬佔用、連接對端 IP/端口、流量統計,是排查網絡擁塞、異常流量的利器。

1. 功能特點

  • 實時顯示源/目標 IP、端口、傳輸速率
  • 支持網段過濾、反向 DNS 解析、端口顯示
  • 交互式界面,按鍵切換顯示模式

2. 安裝依賴

CentOS/RHEL

yum install -y flex byacc libpcap ncurses ncurses-devel libpcap-devel

Debian/Ubuntu

apt-get update && apt-get install -y flex byacc libpcap0.8 libncurses5

3. 編譯安裝(推薐,獲取最新版)

wget https://www.ex-parrot.com/pdw/iftop/download/iftop-1.0pre4.tar.gz
tar zxvf iftop-1.0pre4.tar.gz
cd iftop-1.0pre4
./configure
make && make install

安裝後二進制默認位於 /usr/local/sbin/iftop。

4. 快速安裝(RPM/DEB 包)

CentOS 6/7 (EPEL 源)

yum install -y epel-release
yum install -y iftop

Debian/Ubuntu

apt-get install -y iftop

5. 基本使用

# 默認監控第一張非回環網卡
iftop

# 指定網卡
iftop -i eth0

# 顯示 IP 不解析主機名(加快顯示)
iftop -n

# 顯示端口號
iftop -P

# 監控特定網段
iftop -F 192.168.1.0/24

# 靜默模式輸出到文件(適合腳本)
iftop -t -s 30 > /var/log/iftop_$(date +%F).log

6. 交互式快捷鍵

按鍵功能
h幫助/切換顯示幫助
n切換 IP/主機名顯示
s切換顯示源主機
d切換顯示目標主機
p切換端口顯示
N切換端口號/服務名顯示
t切換顯示模式(兩行/單行/總計)
j/k上下滾動連接列表
f輸入過濾表達式(如 host 192.168.1.100)
q退出

7. 輸出界面解讀

                  12.5Kb      25.0Kb      37.5Kb      50.0Kb     62.5Kb
192.168.1.100  =>  192.168.1.200        5.2Kb      10.4Kb      12.5Kb
                 <=                     1.1Kb       2.2Kb       2.8Kb
TX:  12.5Kb  RX:  2.8Kb  TOTAL: 15.3Kb  (峰值/平均/當前)
  • => 發送流量,<= 接收流量
  • 三列數值:峰值、平均、當前速率
  • 底部 TX/RX/TOTAL 為整網卡匯總

8. 進階過濾表達式

# 僅顯示 80/443 端口流量
iftop -f "port 80 or port 443"

# 排除 SSH 流量
iftop -f "not port 22"

# 監控特定主機
iftop -f "host 10.0.0.50"

總結

iftop 輕量無依賴、啟動即用,是 Linux 服務器網絡故障排查首選工具。配合 -f 過濾表達式與交互式快捷鍵,能快速定位佔用帶寬的進程、IP 或端口。

Copyright © Windows教程網 All Rights Reserved