Linux下如何使用iperf3工具监控网络带宽

在本文中,将介绍使用 iperf3 监控可用网络带宽的步骤。

iperf3 的一个优势是它是 Red Hat Vanilla DVD 的一部分,我们无需下载任何第三方工具。
我们可以使用 yum 命令安装 iperf3,或者我们可以从 Red Hat DVD 复制 rpm 并手动安装
iperf 源代码的最新版本位于 https://github.com/esnet/iperf

在下面的示例中,
iperf 设置了一个大的发送和接收缓冲区大小以最大化吞吐量,并执行 60 秒的测试,这应该足够长以充分运行网络。

Linux上如何查看网络带宽?

在服务器上(IP:10.58.160.101)

# yum install iperf3
或者
# rpm -Uvh /home/jack/iperf3-3.1.7-2.el7.x86_64.rpm
warning: /home/jack/iperf3-3.1.7-2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                ################################# [100%]
Updating/installing...
   1:iperf3-3.1.7-2.el7     ################################# [100%]

在服务器上运行

server # iperf3 -i 10 -s
 warning: this system does not seem to support IPv6 - trying IPv4
 ----------------------------------------------------------
 Server listening on 5201
 ----------------------------------------------------------
 Accepted connection from 10.58.160.103, port 40614
 [  5] local 10.58.160.101 port 5201 connected to 10.58.160.103 port 40616
 [ ID] Interval           Transfer     Bandwidth
 [  5]   0.00-10.00  sec  1.27 GBytes  1.09 Gbits/sec
 [  5]  10.00-20.00  sec  1.27 GBytes  1.09 Gbits/sec
 [  5]  20.00-30.00  sec  1.27 GBytes  1.09 Gbits/sec
 [  5]  30.00-40.00  sec  1.27 GBytes  1.09 Gbits/sec
 [  5]  40.00-50.00  sec  1.27 GBytes  1.09 Gbits/sec
 [  5]  50.00-60.00  sec  1.27 GBytes  1.09 Gbits/sec
 [  5]  60.00-60.04  sec  4.78 MBytes  1.04 Gbits/sec
 - - - - - - - - - - - - - - - - - - - - - - - - 
 [ ID] Interval           Transfer     Bandwidth
 [  5]   0.00-60.04  sec  0.00 Bytes  0.00 bits/sec                  sender
 [  5]   0.00-60.04  sec  7.63 GBytes  1.09 Gbits/sec                  receiver
 ----------------------------------------------------------
 Server listening on 5201
 ----------------------------------------------------------
 Accepted connection from 192.169.173.7, port 35190
 [  5] local 192.169.173.5 port 5201 connected to 192.169.173.7 port 35192
 [ ID] Interval           Transfer     Bandwidth
 [  5]   0.00-10.00  sec  3.55 GBytes  3.05 Gbits/sec
 [  5]  10.00-20.00  sec  3.59 GBytes  3.08 Gbits/sec
 [  5]  20.00-30.00  sec  3.59 GBytes  3.08 Gbits/sec
 [  5]  30.00-40.00  sec  3.59 GBytes  3.08 Gbits/sec
 [  5]  40.00-50.00  sec  3.59 GBytes  3.08 Gbits/sec
 [  5]  50.00-60.00  sec  3.59 GBytes  3.08 Gbits/sec
 [  5]  60.00-60.04  sec  14.4 MBytes  3.14 Gbits/sec
 - - - - - - - - - - - - - - - - - - - - - - - - 
 [ ID] Interval           Transfer     Bandwidth
 [  5]   0.00-60.04  sec  0.00 Bytes  0.00 bits/sec                  sender
 [  5]   0.00-60.04  sec  21.5 GBytes  3.07 Gbits/sec                  receiver
 ----------------------------------------------------------
 Server listening on 5201

选项说明:

-i, --interval n
在定期带宽报告之间暂停n秒;默认值为1,使用0禁用
-s, --server
以服务器模式运行

默认情况下,服务器将使用TCP端口5201,如果要使用其他端口,请使用“-p”选项
-p、 --port n
将服务器端口设置为侦听/连接到n(默认为5201)

在客户端 (192.169.173.7, 10.58.160.103)

# rpm -Uvh /tmp/iperf3-3.1.7-2.el7.x86_64.rpm
warning: /tmp/iperf3-3.1.7-2.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating/installing...
   1:iperf3-3.1.7-2.el7               ################################# [100%]

运行下面的命令,其中带-c的IP是服务器IP(eth0)

client # iperf3 -i 10 -w 1M -t 60 -c 10.58.160.101
 Connecting to host 10.58.160.101, port 5201
 [  4] local 10.58.160.103 port 40616 connected to 10.58.160.101 port 5201
 [ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
 [  4]   0.00-10.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
 [  4]  10.00-20.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
 [  4]  20.00-30.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
 [  4]  30.00-40.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
 [  4]  40.00-50.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
 [  4]  50.00-60.00  sec  1.27 GBytes  1.09 Gbits/sec    0   2.30 MBytes
 - - - - - - - - - - - - - - - - - - - - - - - - 
 [ ID] Interval           Transfer     Bandwidth       Retr
 [  4]   0.00-60.00  sec  7.63 GBytes  1.09 Gbits/sec    0             sender
 [  4]   0.00-60.00  sec  7.63 GBytes  1.09 Gbits/sec                  receiver

选项说明:

-i, --interval n
在定期带宽报告之间暂停 n 秒;默认为 1,使用 0 禁用

-w, --window n[公里]
窗口大小/套接字缓冲区大小(这会发送到服务器并在该端使用)

-t, --time n
以秒为单位的传输时间(默认 10 秒)

-c, --client 主机
在客户端模式下运行,连接到指定的服务器

使用不同的网口测试:

client # iperf3 -i 10 -w 1M -t 60 -c 192.169.173.5
 Connecting to host 192.169.173.5, port 5201
 [  4] local 192.169.173.7 port 35192 connected to 192.169.173.5 port 5201

[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
 [  4]   0.00-10.00  sec  3.56 GBytes  3.06 Gbits/sec    0   2.10 MBytes
 [  4]  10.00-20.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
 [  4]  20.00-30.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
 [  4]  30.00-40.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
 [  4]  40.00-50.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
 [  4]  50.00-60.00  sec  3.59 GBytes  3.08 Gbits/sec    0   2.10 MBytes
 - - - - - - - - - - - - - - - - - - - - - - - - 
 [ ID] Interval           Transfer     Bandwidth       Retr
 [  4]   0.00-60.00  sec  21.5 GBytes  3.08 Gbits/sec    0             sender
 [  4]   0.00-60.00  sec  21.5 GBytes  3.08 Gbits/sec                  receiver

让我们检查每个接口的允许带宽速度

# ethtool eth0 | grep Speed
        Speed: 1000Mb/s

# ethtool eth2 | grep Speed
        Speed: 3000Mb/s

我们看到 eth0 允许的带宽是 1 Gb,我们测试的带宽速度几乎是 1.09Gb/s

而对于另一个接口,我们的允许带宽为 3 Gb/s,其中带宽吞吐量达到 3.08 Gb/s

日期:2020-06-02 22:18:34 来源:oir作者:oir