iperf命令
Iperf 是一個網絡性能測試工具。Iperf可以測試最大TCP和UDP帶寬性能,具有多種參數和UDP特性,可以根據需要調整,可以報告帶寬、延遲抖動和數據包丟失。
下載地址:https://iperf.fr/iperf-download.php#fedora
用戶文檔地址:https://iperf.fr/iperf-doc.php
安裝iperf:
[root@server-A ~]# rpm -ivh iperf3-3.1.3-1.fc24.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:iperf3-3.1.3-1.fc24 ################################# [100%] [root@server-A ~]# rpm -ql iperf3 /usr/bin/iperf3 /usr/lib64/libiperf.so.0 /usr/lib64/libiperf.so.0.0.0 /usr/share/doc/iperf3 /usr/share/doc/iperf3/LICENSE /usr/share/doc/iperf3/README.md /usr/share/doc/iperf3/RELEASE_NOTES /usr/share/man/man1/iperf3.1.gz /usr/share/man/man3/libiperf.3.gz
iperf3選項:
通用選項 | |
---|---|
命令行選項 | 描述 |
-p, --port n | 服務器端口供服務器監聽,客戶端連接。在客戶端和服務器端都應該是相同的。默認是5201 |
--cport n | 指定客戶端端口的選項。(新iPerf 3.1) |
-f, --format [kmKM] |
格式化帶寬數輸出。支持的格式有:
'k' = Kbits/sec 'K' = KBytes/sec
'm' = Mbits/sec 'M' = MBytes/sec
|
-i, --interval n | 設置每次報告之間的時間間隔,單位為秒。如果設置為非零值,就會按照此時間間隔輸出測試報告。默認值為零。 |
-F, --file name | 客戶端:從文件中讀取並寫入網絡,而不是使用隨機數據; 服務器端:從網絡讀取並寫入文件,而不是將數據丟棄。 |
-A, --affinity n/n,m-F | 如果可能的話,設置CPU關聯性(僅為Linux和FreeBSD)。在客戶機和服務器上,您都可以使用這個參數的n形式來設置本地關聯(在這里n是一個CPU數字)。此外,在客戶端,您可以使用n、m的參數形式來覆蓋服務器的親合性。注意,在使用這個特性時,進程只會綁定到一個CPU(而不是一個包含潛在的多個CPU的集合)。 |
-B, --bind host | 綁定到主機一個地址。對於客戶端,這設置了出站接口。對於服務器,這將設置傳入的接口。只適用於多網卡主機。 |
-V, --verbose | 給更詳細的輸出 |
-J, --json | 以JSON格式輸出 |
--logfile file | 將輸出發送到一個日志文件。(新iPerf 3.1) |
--d, --debug | 顯示debug信息 |
-v, --version | 顯示版本信息並退出。 |
-h, --help | 顯示幫助信息 |
服務器選項 | |
命令行選項 | 描述 |
-s, --server | 在服務器模式下運行iPerf。(這一次只允許一次iperf連接) |
-D, --daemon | 在后台運行服務器作為守護進程。 |
-I, --pidfilefile | 使用進程ID編寫一個文件,在作為守護進程運行時最有用。(新iPerf 3.1) |
客戶端選項 | |
命令行選項 | 描述 |
-c, --client host | 在客戶端模式下運行iPerf,連接到在主機上運行的iPerf服務器。 |
--sctp | 使用SCTP而不是TCP(Linux、FreeBSD和Solaris)。(新iPerf 3.1) |
-u, --udp | 使用UDP而不是TCP。參見-b選項。 |
-b, --bandwidth n[KM] | UDP模式使用的帶寬,單位bits/sec。此選項與-u選項相關。默認值是1 Mbit/sec。 |
-t, --time n | 設置傳輸的總時間。Iperf在指定的時間內,重復的發送指定長度的數據包。默認是10秒鍾。參考-l與-n選項。 |
-n, --num n[KM] | 傳送的緩沖器數量。通常情況,Iperf按照10秒鍾發送數據。-n參數跨越此限制,按照指定次數發送指定長度的數據,而不論該操作耗費多少時間。參考-l與-t選項。 |
-k, --blockcount n[KM] | 用於傳輸的塊(數據包)的數量。(而不是-t或-n)也可以看到-t,-l和-n選項 |
-l, --length n[KM] | 設置讀寫緩沖區的長度。TCP方式默認為8KB,UDP方式默認為1470字節。 |
-P, --parallel n | 線程數。指定客戶端與服務端之間使用的線程數。默認是1線程。需要客戶端與服務器端同時使用此參數。 |
-R, --reverse | 以反向模式運行(服務器發送,客戶端接收)。 |
-w, --window n[KM] | 將套接字緩沖區大小設置為指定的值。對於TCP,這設置了TCP窗口的大小。 |
-M, --set-mss n | 嘗試設置TCP最大段大小(MSS)。MSS通常是MTU-40字節的ip報頭。對於以太網,MSS是1460字節(1500字節MTU)。 |
-N, --no-delay | 設置TCP不延遲選項,使Nagle的算法失效。通常情況下,像telnet這樣的交互式應用程序通過禁用。 |
-4, --version4 | 只使用IPv4。 |
-6, --version4 | o只使用IPv6。 |
-S, --tos n | 用於輸出數據包的服務類型。(許多路由器忽略了TOS字段。)您可以使用“0x”前綴指定十六進制值,在八進制中使用“0”前綴,或在十進制中。例如,'0x10'十六進制='020'八進制='16'小數。RFC 1349中指定的圖號是: IPTOS_LOWDELAY minimize delay 0x10 IPTOS_THROUGHPUT maximize throughput 0x08 IPTOS_RELIABILITY maximize reliability 0x04 IPTOS_LOWCOST minimize cost 0x02 |
-L, --flowlabel n | 設置IPv6流標簽(目前僅在Linux上支持)。 |
-Z, --zerocopy | 使用“零拷貝”發送數據的方法,例如sendfile(2),而不是通常的寫入(2)。這使用了更少的CPU。 |
-O, --omit n | 忽略測試的前n秒,跳過TCP TCP慢啟動周期。 |
-T, --title str | 在每個輸出行前面加上這個字符串。 |
-C, --linux-congestion algo | 設置擁塞控制算法(Linux只針對iPerf 3.0、Linux和FreeBSD為iPerf 3.1)。 |
iperf3實例:
帶寬測試通常采用UDP模式,因為能測出極限帶寬、時延抖動、丟包率。在進行測試時,首先以鏈路理論帶寬作為數據發送速率進行測試,例如,從客戶端到服務器之間的鏈路的理論帶寬為100Mbps,先用-b 100M進行測試,然后根據測試結果(包括實際帶寬,時延抖動和丟包率),再以實際帶寬作為數據發送速率進行測試,會發現時延抖動和丟包率比第一次好很多,重復測試幾次,就能得出穩定的實際帶寬。
UDP模式:在client端使用-u選項
server:
[root@server-A ~]# iperf3 -s -V iperf 3.1.3 Linux server-A 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Time: Wed, 20 Sep 2017 16:10:18 GMT Accepted connection from 192.168.1.120, port 41138 Cookie: client-B.1505859092.776727.2dfae62a4 [ 5] local 192.168.1.130 port 5201 connected to 192.168.1.120 port 51883 Starting Test: protocol: UDP, 1 streams, 8192 byte blocks, omitting 0 seconds, 2 second test [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 5] 0.00-1.00 sec 120 KBytes 982 Kbits/sec 1638910.193 ms 0/15 (0%) [ 5] 1.00-2.00 sec 128 KBytes 1.05 Mbits/sec 583573.766 ms 0/16 (0%) [ 5] 2.00-2.05 sec 0.00 Bytes 0.00 bits/sec 583573.766 ms 0/0 (0%) - - - - - - - - - - - - - - - - - - - - - - - - - Test Complete. Summary Results: [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 5] 0.00-2.05 sec 0.00 Bytes 0.00 bits/sec 583573.766 ms 0/31 (0%) CPU Utilization: local/receiver 0.0% (0.0%u/0.0%s), remote/sender 0.0% (0.0%u/0.0%s) iperf 3.1.3 Linux server-A 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 ----------------------------------------------------------- Server listening on 5201 -----------------------------------------------------------
client:
#設置傳輸時間為2秒
[root@client-B ~]# iperf3 -c 192.168.1.130 -t 2 -u Connecting to host 192.168.1.130, port 5201 [ 4] local 192.168.1.120 port 51883 connected to 192.168.1.130 port 5201 [ ID] Interval Transfer Bandwidth Total Datagrams [ 4] 0.00-1.01 sec 128 KBytes 1.04 Mbits/sec 16 [ 4] 1.01-2.00 sec 128 KBytes 1.05 Mbits/sec 16 - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams [ 4] 0.00-2.00 sec 256 KBytes 1.05 Mbits/sec 583573.766 ms 0/31 (0%) [ 4] Sent 31 datagrams iperf Done.
#客戶端同時向服務器端發起30個連接線程,以5Mbps為數據發送速率。 [root@client-B ~]# iperf3 -u -c 192.168.1.130 -b 5M -P 30 -t 60
#以100M為數據發送速率,進行上下行帶寬測試。 #上傳帶寬測試 [root@client-B ~]# iperf3 -u -c 192.168.1.130 -b 100M -t 60 #下載帶寬測試,使用-R選項 [root@client-B ~]# iperf3 -u -c 192.168.1.130 -b 100M -R -t 60
TCP模式:默認使用TCP
server:
[root@server-A ~]# iperf3 -s -V iperf 3.1.3 Linux server-A 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Time: Wed, 20 Sep 2017 16:30:44 GMT Accepted connection from 192.168.1.120, port 41158 Cookie: client-B.1505860318.231455.1c28c3a96 TCP MSS: 1448 (default) [ 5] local 192.168.1.130 port 5201 connected to 192.168.1.120 port 41160 Starting Test: protocol: TCP, 1 streams, 131072 byte blocks, omitting 0 seconds, 2 second test [ ID] Interval Transfer Bandwidth [ 5] 0.00-1.00 sec 499 MBytes 4.18 Gbits/sec [ 5] 1.00-2.00 sec 499 MBytes 4.19 Gbits/sec [ 5] 2.00-2.04 sec 17.8 MBytes 3.79 Gbits/sec - - - - - - - - - - - - - - - - - - - - - - - - - Test Complete. Summary Results: [ ID] Interval Transfer Bandwidth [ 5] 0.00-2.04 sec 0.00 Bytes 0.00 bits/sec sender [ 5] 0.00-2.04 sec 1016 MBytes 4.18 Gbits/sec receiver CPU Utilization: local/receiver 5.4% (0.0%u/5.4%s), remote/sender 0.0% (0.0%u/0.0%s)
client:
#在tcp模式下,客戶端到服務器192.168.1.1上傳帶寬測試,測試時間為60秒。 [root@client-B ~]# iperf3 -c 192.168.1.130 -t 60 Connecting to host 192.168.1.130, port 5201 [ 4] local 192.168.1.120 port 41226 connected to 192.168.1.130 port 5201 [ ID] Interval Transfer Bandwidth Retr Cwnd [ 4] 0.00-1.00 sec 497 MBytes 4.17 Gbits/sec 0 2.03 MBytes [ 4] 1.00-2.00 sec 464 MBytes 3.89 Gbits/sec 0 2.49 MBytes [ 4] 2.00-3.00 sec 508 MBytes 4.25 Gbits/sec 71 1.80 MBytes [ 4] 3.00-4.00 sec 532 MBytes 4.47 Gbits/sec 0 1.88 MBytes [ 4] 4.00-5.00 sec 520 MBytes 4.36 Gbits/sec 0 1.97 MBytes [ 4] 5.00-6.00 sec 475 MBytes 3.98 Gbits/sec 0 2.04 MBytes [ 4] 6.00-7.00 sec 519 MBytes 4.36 Gbits/sec 59 1.48 MBytes ... - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bandwidth Retr [ 4] 0.00-7.52 sec 3.69 GBytes 4.22 Gbits/sec 130 sender [ 4] 0.00-7.52 sec 0.00 Bytes 0.00 bits/sec receiver iperf3: interrupt - the client has terminated
#客戶端同時向服務器端發起30個連接線程。 [root@client-B ~]# iperf3 -c 192.168.1.130 -P 30 -t 60
#進行上下行帶寬測試。 #上傳帶寬測試 [root@client-B ~]# iperf3 -c 192.168.1.130 -t 60 #下載帶寬測試,使用-R選項 [root@client-B ~]# iperf3 -c 192.168.1.130 -R -t 60
iperf3介紹到此結束;有興趣的朋友可以看下用戶文檔,其中也有iperf版本2的詳細介紹
***********************************************************
學習永遠不晚。——高爾基
***********************************************************