Linux - iperf 網絡性能測試工具-測試最大TCP和UDP帶寬性能 介紹&安裝&使用


參考自:https://www.cnblogs.com/jiqing9006/p/10966578.html

iperf簡介:

Iperf 是一個網絡性能測試工具。Iperf可以測試最大TCP和UDP帶寬性能,具有多種參數和UDP特性,可以根據需要調整,可以報告帶寬、延遲抖動和數據包丟失。

 

iperf版本:

iperf 分為兩種版本,unix/linux版和windows版,unix/linux版更新比較快,版本最新。windows版更新慢。windows版的iperf叫jperf,或者xjperf。jperf是在iperf基礎上開發了更好的UI和新的功能。

 

iperf參數說明(命令窗口執行):

[root]# iperf -h
Usage: iperf [-s|-c host] [options]
iperf [-h|--help] [-v|--version]
注:詳細說明見百度百科:https://baike.baidu.com/item/iperf/11067694?fr=aladdin

 

iperf實例:

1、TCP測試

服務器執行:./iperf -s -i 1 -w 1M 這裏是指定Linux,如果是 iperf -s則是windows平台下命令。默認包大小為8kbyte/s
客戶端執行:./iperf -c host -i 1 -w 1M
其中-w表示TCP window size,host需替換成服務器地址。

2、UDP測試

服務器執行:./iperf -u -s
客戶端執行:./iperf -u -c 10.255.255.251 -b 900M -i 1 -w 1M -t 60
其中-b表示使用多少帶寬,1G的線路你可以使用900M進行測試。

 

iperf功能介紹:

1、TCP

  • 測量網絡帶寬
  • 報告MSS/MTU值的大小和觀測值
  • 支持TCP窗口值通過套接字緩沖
  • 當P線程或Win32線程可用時,支持多線程。客戶端與服務端支持同時多重連接

2、UDP

  • 客戶端可以創建指定帶寬的UDP流
  • 測量丟包
  • 測量延遲
  • 支持多播
  • 當P線程可用時,支持多線程。客戶端與服務端支持同時多重連接(不支持Windows)

3、在適當的地方,選項中可以使用K(kilo-)和M(mega-)。例如131072字節可以用128K代替。

4、可以指定運行的總時間,甚至可以設置傳輸的數據總量。

5、在報告中,為數據選用最合適的單位。

6、服務器支持多重連接,而不是等待一個單線程測試。

7、在指定時間間隔重復顯示網絡帶寬,波動和丟包情況。

8、服務器端可作為后台程序運行。

9、服務器端可作為Windows 服務運行。

10、使用典型數據流來測試鏈接層壓縮對於可用帶寬的影響。

 

iperf在Ubuntu上安裝:

1、iperf的github地址

https://github.com/esnet/iperf/releases

2、解壓到指定目錄

sudo tar -zvxf iperf-3.6.tar.gz -C /usr/local

3、進入目錄配置,編譯,安裝

./configure
make
sudo make install

4、報錯

iperf3: error while loading shared libraries: libiperf.so.0: cannot open shared object file: No such file or directory

5、手動執行

sudo /sbin/ldconfig

6、可以訪問了

# iperf3 -v
iperf 3.6 (cJSON 1.5.2)
Linux JQ-Mac 4.15.0-45-generic #48~16.04.1-Ubuntu SMP Tue Jan 29 18:03:48 UTC 2019 x86_64
Optional features available: CPU affinity setting, IPv6 flow label, TCP congestion algorithm setting, sendfile / zerocopy, socket pacing, authentication

7、開啟服務

# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

8、確保服務端開啟5201端口(可以開啟服務就忽略這一步)

vim /etc/sysconfig/iptables
/etc/init.d/iptables restart

9、測試訪問

# iperf3 -c 192.168.1.200
Connecting to host 192.168.1.200, port 5201
[  5] local 192.168.1.228 port 58092 connected to 192.168.1.200 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  11.3 MBytes  94.5 Mbits/sec    0   24.0 KBytes       
[  5]   1.00-2.00   sec  11.2 MBytes  94.1 Mbits/sec    0   26.9 KBytes       
[  5]   2.00-3.00   sec  11.2 MBytes  94.1 Mbits/sec    0   28.3 KBytes       
[  5]   3.00-4.00   sec  11.2 MBytes  94.2 Mbits/sec    0   43.8 KBytes       
[  5]   4.00-5.00   sec  11.2 MBytes  94.2 Mbits/sec    0   43.8 KBytes       
[  5]   5.00-6.00   sec  11.2 MBytes  93.7 Mbits/sec    0   43.8 KBytes       
[  5]   6.00-7.00   sec  11.1 MBytes  93.3 Mbits/sec    0   43.8 KBytes       
[  5]   7.00-8.00   sec  11.3 MBytes  94.4 Mbits/sec    0   66.5 KBytes       
[  5]   8.00-9.00   sec  11.3 MBytes  94.8 Mbits/sec    0    100 KBytes       
[  5]   9.00-10.00  sec  11.1 MBytes  93.2 Mbits/sec    0    100 KBytes       
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec   112 MBytes  94.0 Mbits/sec    0             sender
[  5]   0.00-10.04  sec   112 MBytes  93.6 Mbits/sec                  receiver

iperf Done.

10、執行命令將打印信息追加到文件(服務器和客戶端都在同一台機器上)

//確保服務器開啟的情況下,在客戶端執行
// -c:表示自己是客戶端
// 127.0.0.1:表示服務器地址
// -b 40M:以40Mbits/sec的速度
// -t 10:測試10秒鍾
// 1.txt:表示追加的文件名相對路徑
iperf3 -c 127.0.0.1 -b 40M -t 10 >> 1.txt

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM