在 Windows 上用 iperf 測網速:iperf3 官方不支援,改用 iperf2|iperf 網路測速 2

iperf3 官方只支援 Linux、FreeBSD、macOS,FAQ 建議 Windows 改用 iperf2。在 Windows 10 和 Debian 13 實測 iperf2 2.2.2:從 SourceForge 下載並用 Get-FileHash 驗證、Windows 當伺服器時防火牆擋住的樣子和規則怎麼加、-R、--full-duplex、-P、-e 的輸出,以及 -d 被防火牆擋住時不會報錯、只少一個方向的結果。

搜尋「iperf3 Windows」會找到很多下載點,但 iperf3 官方 FAQ 寫得很直接:iperf3 沒有正式支援 Windows,Windows 上建議用 iperf2。iperf2 在 SourceForge 有官方編譯的 Windows 版,兩端都用 iperf2 就好。

iperf2 和 iperf3 不能互通,Linux 那端也要用 iperf2(套件名稱是 iperf)。兩者的差別見〈利用 iperf 測試網路效能〉。

實驗環境:

角色 系統 iperf2
Windows Windows 10 專業版 22H2 虛擬機 2.2.2(SourceForge 官方 win64)
Linux Debian 13 虛擬機 2.2.1(apt install iperf)

兩台虛擬機在同一台實體主機上,速度數字是虛擬網路的表現,不代表實體網路,這篇只拿來看用法和輸出。

下載並驗證

到 SourceForge 的 iperf2 專案(sourceforge.net/projects/iperf2/files/)下載 iperf-2.2.2-win64.exe 和同目錄的 iperf-2.2.2-SHA256SUMS.txt。這個 exe 就是 iperf 本體,不是安裝程式,放在任何目錄都能直接執行。

用 PowerShell 下載和驗證:

New-Item -ItemType Directory C:\iperf
Set-Location C:\iperf
Invoke-WebRequest -UseBasicParsing -UserAgent "Wget/1.21" -OutFile iperf.exe `
  -Uri https://downloads.sourceforge.net/project/iperf2/iperf-2.2.2-win64.exe
Invoke-WebRequest -UseBasicParsing -UserAgent "Wget/1.21" -OutFile SUMS.txt `
  -Uri https://downloads.sourceforge.net/project/iperf2/iperf-2.2.2-SHA256SUMS.txt
(Get-FileHash .\iperf.exe -Algorithm SHA256).Hash.ToLower()
Select-String -Path SUMS.txt -Pattern win64 | ForEach-Object { $_.Line }
de60d0116757dde60e70d4f113c93a21dc48a36c0b30087551dac11e8eab8d1d
de60d0116757dde60e70d4f113c93a21dc48a36c0b30087551dac11e8eab8d1d  iperf-2.2.2-win64.exe

兩個雜湊值一樣,檔案就沒被改過。-UserAgent 不能省:這次拿掉它再下載一次,拿到的是 113,321 bytes、開頭是 <! 的 HTML 網頁,不是程式。用瀏覽器下載的話沒有這個問題,一樣要對雜湊值。

PS C:\iperf> .\iperf.exe -v
iperf 2.2.2 (11 November 2026) pthreads (community)

社群編譯的 iperf3 Windows 版,ESnet 的〈Obtaining iperf3〉頁面列了一個下載點,但 2026-12-05 測試時連線沒有回應,這次沒有測。這類檔案不是官方發行的,用之前至少要確認來源,FAQ 也提醒不是所有選項都能用。

Windows 當客戶端

Linux 開伺服器:

iperf -s

Windows 連過去,-e 會多印一些資訊:

PS C:\iperf> .\iperf.exe -c 192.168.122.127 -t 5 -e
------------------------------------------------------------
Client connecting to 192.168.122.127, TCP port 5001 with pid 4324 (1/0 flows/load)
Write buffer size: 131072 Byte
TOS defaults to 0x0 (dscp=0,ecn=0) (Nagle on)
TCP window size: 64.0 KByte (default)
------------------------------------------------------------
[ ID] Interval        Transfer    Bandwidth       Write/Err
[  1] 0.00-5.02 sec  4.22 GBytes  7.23 Gbits/sec  34586/0

Windows 這端用 -e 只多了 Write/Err(寫入次數和錯誤數)。同樣用 -e,Linux 當客戶端時還會多出重傳(Rtry)、壅塞視窗(Cwnd)、往返時間(RTT),下一節的輸出看得到。

不需要在 Windows 防火牆加任何規則:連線是 Windows 主動往外連的。

Windows 當伺服器:先被防火牆擋住

在 Windows 上開伺服器:

.\iperf.exe -s
Server listening on TCP port 5001
TCP window size: 64.0 KByte (default)

Windows 上確實在聽 5001 port,但 Linux 連過去:

$ iperf -c 192.168.122.223 -t 3
[  1] tcp connect to 192.168.122.223 port 5001 failed (Connection timed out) on 2026-12-05 15:02:25 (UTC)

real    2m13.940s

等了兩分多鐘才放棄。這台 Windows 的網路設定檔是「公用」,三種設定檔的防火牆都開著,沒有規則允許的連入連線會被丟掉。

上面是透過 SSH 執行的,沒有任何提示。在 Windows 桌面上直接執行 iperf.exe -s,會跳出這個視窗:

Windows Defender 防火牆已封鎖此應用程式的部分功能:名稱 iperf、發行者不明、預設勾選公用網路
Windows 10 桌面上執行 iperf.exe -s 時跳出的防火牆視窗。這台的網路是「公用」,所以預設勾的是公用網路;發行者顯示「不明」,因為 iperf.exe 沒有數位簽章。

視窗還開著、什麼都還沒按,防火牆裡就已經多了兩條規則:

iperf dir=Inbound action=Block profile=Public enabled=True proto=TCP prog=C:\iperf\iperf.exe
iperf dir=Inbound action=Block profile=Public enabled=True proto=UDP prog=C:\iperf\iperf.exe

是封鎖規則,不是允許。Microsoft 的〈Windows Firewall rules〉文件寫明:使用者按取消或關掉提示,就會建立封鎖規則,通常 TCP、UDP 各一條;使用者不是系統管理員時,不管按什麼都會建立封鎖規則。按「允許存取」之後規則會變成什麼,這次沒有測到(按鈕需要提升權限,透過虛擬機的鍵盤操作沒有成功)。

封鎖規則比允許規則優先

這兩條封鎖規則很容易被忽略。之後就算照下面的做法開了 port,還是連不進來。三種情況各測一次(iperf2 伺服器一直開著):

Windows 防火牆的規則 Linux 連過去
只有「TCP 5001 允許」 304 Mbits/sec
再加上「iperf.exe 封鎖(公用)」 Connection timed out
把封鎖規則刪掉 1.28 Gbits/sec

同一份文件寫明:明確的封鎖規則優先於任何衝突的允許規則。所以「明明開了 port 還是連不到」時,先找有沒有針對 iperf 的封鎖規則:

Get-NetFirewallRule -DisplayName iperf* | Format-Table DisplayName, Action, Profile, Enabled
Get-NetFirewallRule -DisplayName iperf | Where-Object Action -eq Block | Remove-NetFirewallRule

用指令開 port

用系統管理員身分的 PowerShell 加一條規則,只開 5001 port、只允許同網段的電腦:

New-NetFirewallRule -DisplayName 'iperf2 TCP 5001' -Direction Inbound `
  -Protocol TCP -LocalPort 5001 -RemoteAddress 192.168.122.0/24 -Action Allow

測完要移除:

Remove-NetFirewallRule -DisplayName 'iperf2 TCP 5001'

要測 UDP(〈用 iperf3 測 UDP〉),另外加一條 -Protocol UDP 的規則。

加上規則後,Linux 當客戶端:

$ iperf -c 192.168.122.223 -t 4 -e
[  1] local 192.168.122.127%ens2 port 55206 connected with 192.168.122.223 port 5001 (icwnd/mss/irtt=14/1460/744) (ct=0.89 ms)
[ ID] Interval            Transfer    Bandwidth       Write/Err  Rtry     InF(pkts)/Cwnd(pkts)/RTT(var)        NetPwr
[  1] 0.0000-4.0548 sec   218 MBytes   452 Mbits/sec  1748/0         0        0K(0)/14K(10)/744(372) us  75904

Windows 伺服器那邊同時印出它收到的結果:

[  1] local 192.168.122.223 port 5001 connected with 192.168.122.127 port 55206 (peer 2.2.1-rc) on 2026-12-05 23:02:59.926 (台北標準時間)
[ ID] Interval        Transfer    Bandwidth       Reads=Dist
[  1] 0.00-4.04 sec   218 MBytes   453 Mbits/sec  4813=2:2370:3:2380:2:14:1:41

peer 2.2.1-rc 是對方的版本。這次 Linux 傳給 Windows 只有 453 Mbits/sec,反方向卻有好幾 Gbits/sec;原因這次沒有追查,虛擬網路的數字不要拿來下結論。

雙向測試:-d 和 --full-duplex 不一樣

iperf2 有三種雙向的測法:

參數 做法 連線
-R 只測反方向:伺服器傳給客戶端 同一條連線
--full-duplex 兩個方向同時傳 同一條連線
-d 兩個方向同時傳 伺服器另外反連回客戶端
-r 兩個方向輪流傳 同上
flowchart TB W["Windows 客戶端"] -->|"四種測法都先建這條: Windows 連 Linux :5001"| L["Linux 伺服器"] L -->|"只有 -d、-r: 伺服器另外反連 Windows :5001"| F["Windows 防火牆 沒有開放就丟掉"]

圖說:-d 和 -r 的反方向,是伺服器主動連回客戶端,客戶端也要開放連入。

把 Windows 的防火牆規則拿掉,Windows 當客戶端連 Linux:

PS C:\iperf> .\iperf.exe -c 192.168.122.127 -t 4 -d
Client connecting to 192.168.122.127, TCP port 5001
Server listening on TCP port 5001
[  1] local 192.168.122.223 port 53619 connected with 192.168.122.127 port 5001
[ ID] Interval       Transfer     Bandwidth
[  1] 0.00-4.01 sec  1.96 GBytes  4.19 Gbits/sec

沒有任何錯誤,但只有一個方向的結果。Linux 伺服器的紀錄裡有 Client connecting to 192.168.122.223, TCP port 5001,之後就沒有下文:反連的連線被 Windows 防火牆丟掉了。不仔細看,很容易以為雙向測試做完了。

同樣條件下改用 --full-duplex:

[  1] local 192.168.122.223 port 53620 connected with 192.168.122.127 port 5001 (full-duplex)
[ ID] Interval       Transfer     Bandwidth
[  1] 0.00-4.00 sec   348 MBytes   729 Mbits/sec
[ *1] 0.00-4.07 sec   171 MBytes   352 Mbits/sec
[SUM] 0.00-4.07 sec   518 MBytes  1.07 Gbits/sec

兩個方向都有,[ *1] 是反方向,[SUM] 是加總。-R 也一樣不需要開放客戶端。客戶端在防火牆或 NAT 後面時,用 -R 和 --full-duplex,不要用 -d、-r。

多條連線

$ iperf -c 192.168.122.223 -t 4 -e -P 4
[  1] 0.0000-4.0309 sec   249 MBytes   519 Mbits/sec ...
[  2] 0.0000-4.0275 sec   666 MBytes  1.39 Gbits/sec ...
[  3] 0.0000-4.0493 sec  3.88 MBytes  8.03 Mbits/sec ...
[  4] 0.0000-4.0515 sec  3.75 MBytes  7.76 Mbits/sec ...
[SUM-4] 0.0000-4.0275 sec   923 MBytes  1.92 Gbits/sec  7387/0         0

看 [SUM-4] 那一行的總和。各條連線分到的速度可能差很多,這次有兩條只有 8 Mbits/sec。

常用參數對照

iperf2 和 iperf3 有很多參數同名,但不是全部:

用途 iperf2 iperf3
預設 port 5001 5201
反方向 -R -R
雙向同時,同一條連線 --full-duplex --bidir
雙向同時,伺服器反連 -d 沒有
雙向輪流 -r 沒有
更多資訊 -e -V
測試時間 -t(預設 10 秒) -t(預設 10 秒)
多條連線 -P -P

iperf2 的參數取自 Debian 13 上 iperf --help 的輸出,iperf3 的取自官方文件〈Invoking iperf3〉。

參考來源

iperf 網路測速 下一篇

關於作者

已發表 391 篇文章