利用iperf3快速测试两台VPS服务器之间的网络速度

快速发现两台 Linux 服务器之间的速度通常是复制大文件,这是一件吃力不讨好的苦差事。

iPerf3 是一种流行的网络性能测量和测试工具,可以轻松安装在大多数 Linux 操作系统上。本文将介绍如何在运行 Ubuntu 22.04 操作系统的 Linux 主机上安装 iPerf3。它还将展示如何启动 iPerf3 服务器(用于接收流量)以及如何启动 iPerf3 客户端(用于启动对运行 iPerf3 服务器的主机的网络性能测试)的简要示例。

安装 iPerf3

首先,使用该sudo apt -y update命令更新 apt 软件包管理器的可以安装或升级的软件包列表。

sudo apt -y update

接下来,使用命令安装 iPerf3 sudo apt -y install iperf3

sudo apt -y install iperf3

您可以使用该iperf3 -v命令确认 iPerf3 已安装,该命令将显示当前安装的 iPerf3 版本和当前 Linux 内核版本的信息。

iperf3 -v

该命令的输出示例如下所示。

root@H1:/# iperf3 -v
iperf 3.9 (cJSON 1.7.13)
Linux H1 5.4.0-109-generic #123-Ubuntu SMP Fri Apr 8 09:10:54 UTC 2022 x86_64
Optional features available: CPU affinity setting, IPv6 flow label, SCTP, TCP congestion algorithm setting, sendfile / zerocopy, socket pacing, authentication

启动 iPerf3 服务器

您可以使用以下命令确认 Ubuntu 22.04 主机能够充当 iPerf3 服务器iperf3 -s

iperf3 -s

该命令的输出示例如下所示。如果此命令的输出表明 iPerf3 服务器正在侦听特定端口,则 iPerf3 服务器正在按预期工作。

root@H2:/# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

默认情况下,iPerf3 服务器将侦听主机所有活动接口上的新连接。如果您希望 iPerf3 服务器侦听特定接口,可以使用该iperf3 -s -B <ip-address>命令。下面显示了一个示例,其中指示 iPerf3 服务器侦听 IP 地址 192.0.2.2。

root@H2:/# iperf3 -s -B 192.0.2.2
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

启动 iPerf3 客户端

您可以使用以下命令确认 Ubuntu 22.04 主机能够充当 iPerf3 客户端iperf3 -c <server-ip-address>

iperf3 -c <server-ip-address>

下面显示了一个示例,其中 iPerf3 客户端需要连接的服务器的 IP 地址是 192.0.2.2。

root@H1:/# iperf3 -c 192.0.2.2
Connecting to host 192.0.2.2, port 5201
[  5] local 192.0.2.1 port 35946 connected to 192.0.2.2 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  3.87 GBytes  33.2 Gbits/sec   57    692 KBytes
[  5]   1.00-2.00   sec  3.63 GBytes  31.2 Gbits/sec    0    812 KBytes
[  5]   2.00-3.00   sec  3.69 GBytes  31.7 Gbits/sec    0    923 KBytes
[  5]   3.00-4.00   sec  3.72 GBytes  32.0 Gbits/sec    0   1.00 MBytes
[  5]   4.00-5.00   sec  3.65 GBytes  31.3 Gbits/sec    0   1.00 MBytes
[  5]   5.00-6.00   sec  4.12 GBytes  35.4 Gbits/sec    0   1.00 MBytes
[  5]   6.00-7.00   sec  3.60 GBytes  30.9 Gbits/sec    0   1.00 MBytes
[  5]   7.00-8.00   sec  3.68 GBytes  31.6 Gbits/sec    0   1.09 MBytes
[  5]   8.00-9.00   sec  4.02 GBytes  34.5 Gbits/sec    0   1.12 MBytes
[  5]   9.00-10.00  sec  3.84 GBytes  33.0 Gbits/sec    0   1.31 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate         Retr
[  5]   0.00-10.00  sec  37.8 GBytes  32.5 Gbits/sec   57             sender
[  5]   0.00-10.00  sec  37.8 GBytes  32.5 Gbits/sec                  receiver

iperf Done.

当 iPerf3 客户端针对特定 iPerf3 服务器时,您将在 iPerf3 服务器上看到类似于以下内容的输出。

root@H2:/# iperf3 -s -B 192.0.2.2
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 192.0.2.1, port 35944
[  5] local 192.0.2.2 port 5201 connected to 192.0.2.1 port 35946
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec  3.87 GBytes  33.2 Gbits/sec
[  5]   1.00-2.00   sec  3.63 GBytes  31.2 Gbits/sec
[  5]   2.00-3.00   sec  3.69 GBytes  31.7 Gbits/sec
[  5]   3.00-4.00   sec  3.72 GBytes  32.0 Gbits/sec
[  5]   4.00-5.00   sec  3.65 GBytes  31.3 Gbits/sec
[  5]   5.00-6.00   sec  4.12 GBytes  35.4 Gbits/sec
[  5]   6.00-7.00   sec  3.60 GBytes  30.9 Gbits/sec
[  5]   7.00-8.00   sec  3.68 GBytes  31.6 Gbits/sec
[  5]   8.00-9.00   sec  4.02 GBytes  34.5 Gbits/sec
[  5]   9.00-10.00  sec  3.84 GBytes  33.0 Gbits/sec
[  5]  10.00-10.00  sec   392 KBytes  25.1 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-10.00  sec  37.8 GBytes  32.5 Gbits/sec                  receiver
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

此输出表明 iPerf3 服务器成功接受来自 iPerf3 客户端的连接,并且能够与客户端交换数据。

测试UDP连接状况:
[code]iperf3 -c 18.182.13.148 -u -R[/code]

评论区
头像