作為一個網(wǎng)絡(luò)工程師經(jīng)常會遇到這種情況,需要在兩點間測試實際可跑帶寬。
帶寬小的線路可以搭個FTP服務(wù)器,或者直接用scp拷文件這種方式,如果線路超過10G以上就不好用了,一方面需要準備大文件,另一方面磁盤的讀寫性能也影響到測試結(jié)果的準確性,這時這個小巧的開源軟件就派上用場了。
iPerf是用于主動測量IP網(wǎng)絡(luò)上最大可承載帶寬的工具。它支持調(diào)整與時序,緩沖區(qū)和協(xié)議(TCP,UDP,SCTP與IPv4和IPv6)有關(guān)的各種參數(shù)。對于每個測試,它都會報告帶寬,丟失和其他參數(shù)。官方地址https://iperf.fr/
iPerf功能
- TCP和SCTP
- 測量帶寬
- 報告MSS / MTU大小和觀察的讀取大小。
- 通過套接字緩沖區(qū)支持TCP窗口大小。
- UDP
- 客戶端可以創(chuàng)建指定帶寬的UDP流。
- 測量數(shù)據(jù)包丟失
- 測量延遲抖動
- 多播能力
跨平臺:Windows,Linux,Android,MacOS X,F(xiàn)reeBSD,OpenBSD,NetBSD,VxWorks,Solaris ...基本所有的系統(tǒng)都支持了。軟件下載地址https://iperf.fr/iperf-download.php,當前最新版本為iperf3
安裝
CentOS 可以直接用 yum install iperf或yum install iperf3安裝
使用(我使用的是iperf3)
- TCP模式
服務(wù)器端:
[root@10-57-22-228 ~]# iperf3 -s -p 1234 -i 1
-----------------------------------------------------------
Server listening on 1234
客戶端:
[root@10-57-22-128 ~]# iperf3 -c 10.57.22.228 -p 1234 -i 1 -t 10
Connecting to host 10.57.22.228, port 1234
[ 4] local 10.57.22.128 port 38079 connected to 10.57.22.228 port 1234
[ ID] Interval Transfer Bandwidth Retr Cwnd
[ 4] 0.00-1.00 sec 112 MBytes 941 Mbits/sec 250 270 KBytes
[ 4] 1.00-2.00 sec 111 MBytes 932 Mbits/sec 305 369 KBytes
[ 4] 2.00-3.00 sec 111 MBytes 933 Mbits/sec 978 259 KBytes
[ 4] 3.00-4.00 sec 111 MBytes 930 Mbits/sec 358 349 KBytes
[ 4] 4.00-5.00 sec 111 MBytes 931 Mbits/sec 654 286 KBytes
[ 4] 5.00-6.00 sec 111 MBytes 933 Mbits/sec 360 354 KBytes
[ 4] 6.00-7.00 sec 111 MBytes 934 Mbits/sec 417 366 KBytes
[ 4] 7.00-8.00 sec 111 MBytes 934 Mbits/sec 696 329 KBytes
[ 4] 8.00-9.00 sec 111 MBytes 931 Mbits/sec 660 209 KBytes
[ 4] 9.00-10.00 sec 110 MBytes 926 Mbits/sec 912 202 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-10.00 sec 1.09 GBytes 932 Mbits/sec 5590 sender
[ 4] 0.00-10.00 sec 1.08 GBytes 931 Mbits/sec receiver
在tcp模式下,客戶端到服務(wù)器10.57.22.228上傳帶寬測試,測試時間為10秒。
[root@10-57-22-128 ~]# iperf3 -c 10.57.22.228 -p 1234 -d -t 10
send_parameters:
{
"tcp": true,
"omit": 0,
"time": 10,
"parallel": 1,
"len": 131072,
"client_version": "3.1.7"
}
Connecting to host 10.57.22.228, port 1234
SNDBUF is 16384, expecting 0
RCVBUF is 87380, expecting 0
Congestion algorithm is cubic
[ 4] local 10.57.22.128 port 38112 connected to 10.57.22.228 port 1234
tcpi_snd_cwnd 225 tcpi_snd_mss 1448 tcpi_rtt 2379
[ ID] Interval Transfer Bandwidth Retr Cwnd
[ 4] 0.00-1.00 sec 112 MBytes 940 Mbits/sec 317 318 KBytes
tcpi_snd_cwnd 187 tcpi_snd_mss 1448 tcpi_rtt 2001
[ 4] 1.00-2.00 sec 110 MBytes 923 Mbits/sec 1763 264 KBytes
tcpi_snd_cwnd 255 tcpi_snd_mss 1448 tcpi_rtt 1908
[ 4] 2.00-3.00 sec 109 MBytes 914 Mbits/sec 1741 361 KBytes
tcpi_snd_cwnd 261 tcpi_snd_mss 1448 tcpi_rtt 2795
[ 4] 3.00-4.00 sec 109 MBytes 916 Mbits/sec 1729 369 KBytes
tcpi_snd_cwnd 198 tcpi_snd_mss 1448 tcpi_rtt 2081
[ 4] 4.00-5.00 sec 109 MBytes 917 Mbits/sec 2040 280 KBytes
tcpi_snd_cwnd 255 tcpi_snd_mss 1448 tcpi_rtt 5058
[ 4] 5.00-6.00 sec 106 MBytes 889 Mbits/sec 4096 361 KBytes
tcpi_snd_cwnd 190 tcpi_snd_mss 1448 tcpi_rtt 2277
[ 4] 6.00-7.00 sec 109 MBytes 916 Mbits/sec 2050 269 KBytes
tcpi_snd_cwnd 255 tcpi_snd_mss 1448 tcpi_rtt 2336
[ 4] 7.00-8.00 sec 110 MBytes 919 Mbits/sec 1702 361 KBytes
tcpi_snd_cwnd 262 tcpi_snd_mss 1448 tcpi_rtt 3349
[ 4] 8.00-9.00 sec 108 MBytes 910 Mbits/sec 2175 370 KBytes
tcpi_snd_cwnd 199 tcpi_snd_mss 1448 tcpi_rtt 3639
send_results
{
"cpu_util_total": 4.364935,
"cpu_util_user": 0.135769,
"cpu_util_system": 4.285394,
"sender_has_retransmits": 1,
"congestion_used": "cubic",
"streams": [{
"id": 1,
"bytes": 1138941776,
"retransmits": 23838,
"jitter": 0,
"errors": 0,
"packets": 0
}]
}
get_results
{
"cpu_util_total": 5.207115,
"cpu_util_user": 0.278441,
"cpu_util_system": 4.931552,
"sender_has_retransmits": -1,
"congestion_used": "cubic",
"streams": [{
"id": 1,
"bytes": 1137687808,
"retransmits": -1,
"jitter": 0,
"errors": 0,
"packets": 0
}]
}
[ 4] 9.00-10.00 sec 103 MBytes 867 Mbits/sec 6225 281 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-10.00 sec 1.06 GBytes 911 Mbits/sec 23838 sender
[ 4] 0.00-10.00 sec 1.06 GBytes 910 Mbits/sec receiver
iperf Done.
進行上下行帶寬測試。
更多功能使用Iperf3 --help查看說明