iftop 是類似 top 的網絡流量實時監控工具,能顯示網卡當前帶寬佔用、連接對端 IP/端口、流量統計,是排查網絡擁塞、異常流量的利器。
yum install -y flex byacc libpcap ncurses ncurses-devel libpcap-devel
apt-get update && apt-get install -y flex byacc libpcap0.8 libncurses5
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。
yum install -y epel-release
yum install -y iftop
apt-get install -y iftop
# 默認監控第一張非回環網卡
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
| 按鍵 | 功能 |
|---|---|
| h | 幫助/切換顯示幫助 |
| n | 切換 IP/主機名顯示 |
| s | 切換顯示源主機 |
| d | 切換顯示目標主機 |
| p | 切換端口顯示 |
| N | 切換端口號/服務名顯示 |
| t | 切換顯示模式(兩行/單行/總計) |
| j/k | 上下滾動連接列表 |
| f | 輸入過濾表達式(如 host 192.168.1.100) |
| q | 退出 |
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 (峰值/平均/當前)
=> 發送流量,<= 接收流量# 僅顯示 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 或端口。