使用Iperf诊断网络速度

安装Iperf


Debian和Ubuntu

可以在Debian和Ubuntu使用apt-get来安装

  1. apt-get install iperf

CentOS

CentOS官方源没有Iperf。我们可以使用RPMForge源来安装,不过安装前需要把这个源安装到系统里。
CentOS 7:

  1. wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
  2. rpm -Uvh rpmforge-release-1.5.3-1.el7.rf.x86_64.rpm
  3. yum update
  4. yum install iperf

CentOS 6

  1. wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-1.el6.rf.x86_64.rpm
  2. rpm -Uvh rpmforge-release-0.5.2-1.el6.rf.x86_64.rpm
  3. yum update
  4. yum install iperf

Fedora:

  1. yum update
  2. yum install iperf

Arch Linux:

  1. pacman -S iperf

Gentoo:

  1. emerge iperf

使用Iperf



Iperf需要在你要测试连接的两台服务器上安装。

TCP Clients & Servers

Iperf需要在两台机器分别扮演客户端和服务端角色。客户端来连接你要测试网速的服务器。
1.在你要测的服务器上启动服务器模式:

  1. iperf -s

将输出如下:

————————————————————
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
————————————————————

2.在你另一台机器,连接上一台机器,把198.51.100.5替换为以上的机器IP

  1. iperf -c 198.51.100.5

类似输出如下:

————————————————————
Client connecting to 198.51.100.5, TCP port 5001
TCP window size: 45.0 KByte (default)
————————————————————
[ 3] local 198.51.100.6 port 50549 connected with 198.51.100.5 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 142 MBytes 119 Mbits/sec

3.在服务端将看到如下输出:

————————————————————
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
————————————————————
[ 4] local 198.51.100.5 port 5001 connected with 198.51.100.6 port 50549
[ ID] Interval Transfer Bandwidth
[ 4] 0.0-10.2 sec 142 MBytes 117 Mbits/sec

4.CTRL + c来停止Iperf进程

UDP Clients & Servers

使用Iperf,你也可以来测试UDP连接的最大吞吐量
1.启动UDP Iperf服务器

  1. iperf -s -u

输出如下:

————————————————————
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size: 208 KByte (default)
————————————————————

2.在客户端连接以上的服务器,替换198.51.100.5为你自己的

  1. iperf -c 198.51.100.5 -u

-u选择表示告诉Iperf使用UDP连接。输出如下:

————————————————————
Client connecting to 198.51.100.5, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 208 KByte (default)
————————————————————
[ 3] local 198.51.100.6 port 58070 connected with 198.51.100.5 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 1.25 MBytes 1.05 Mbits/sec
[ 3] Sent 893 datagrams
[ 3] Server Report:
[ 3] 0.0-10.0 sec 1.25 MBytes 1.05 Mbits/sec 0.084 ms 0/ 893 (0%)

从输出我们可以看到1.05 Mbits/sec比我们收到数据的速度要小。这是因为Iperf默认限制了UDP客户端为1Mbit每秒。
3.你可以使用-b选项来更改,如:

  1. iperf -c 198.51.100.5 -u -b 150m

输出如下:

———————————————————–
Client connecting to 198.51.100.5, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 208 KByte (default)
————————————————————
[ 3] local 198.51.100.6 port 41083 connected with 198.51.100.5 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 145 MBytes 122 Mbits/sec
[ 3] Sent 103625 datagrams
[ 3] Server Report:
[ 3] 0.0-10.3 sec 136 MBytes 111 Mbits/sec 13.488 ms 6464/103623 (6.2%)

发布于:2019-11-21 19:23:16