一、iperf工具安装:

1、获取iperf源码安装包(iperf-3.0.5.tar.gz)

https://downloads.es.net/pub/iperf/

2、将iperf安装包上传到服务器/tmp/目录并解压

[root@localhost /]#cd /tmp/
[root@localhost tmp]#tar –zxvf iperf-3.0.5.tar.gz

3、编译并安装iperf

[root@localhost tmp]# cd iperf-3.0.5
[root@localhost iperf-3.0.5]#./configure
[root@localhost stress-1.0.4]# make
[root@localhost stress-1.0.4]#make install

4、编译安装成功后,可以在系统命令中找到iperf命令

[root@localhost iperf-3.0.5]# iperf
iperf3 
[root@localhost bin]# find /usr/local/|grep iperf
/usr/local/bin/iperf3

注:错误及解决方法:

[root@localhost bin]# iperf3 -s
iperf3: error while loading shared libraries: libiperf.so.0: cannot open shared object file: No such file or directory

问题原因:
Linux系统中找不到libiperf.so.0 库文件,导致执行iperf3 –s时提示缺少相关lib库
解决方法:
通过find /usr/local/lib/ |grep iperf查找其他服务器上是否存在该lib库文件,查询到后拷贝libiperf.so.0库文件到此台服务器/usr/local/lib/目录下

connect error: No route to host(errno:113)

出错原因:server端的防火墙设置了过滤规则

解决办法:使用iptables关闭server端的防火墙

1.暂时关闭

$sudo service iptables stop

2.打开

$sudo service iptables start

3.永久打开和关闭

$sudo chkconfig iptables on

$sudo chkconfig iptables off

二、iperf工具使用方法:

参数说明
-s 以server模式启动,eg:iperf -s
-c host以client模式启动,host是server端地址,eg:iperf -c 222.35.11.23

通用参数
-f [kmKM] 分别表示以Kbits, Mbits, KBytes, MBytes显示报告,默认以Mbits为单位,eg:iperf -c 222.35.11.23 -f K
-i sec 以秒为单位显示报告间隔,eg:iperf -c 222.35.11.23 -i 2
-l 缓冲区大小,默认是8KB,eg:iperf -c 222.35.11.23 -l 16
-m 显示tcp最大mtu值
-o 将报告和错误信息输出到文件eg:iperf -c 222.35.11.23 -o ciperflog.txt
-p 指定服务器端使用的端口或客户端所连接的端口eg:iperf -s -p 9999;iperf -c 222.35.11.23 -p 9999
-u 使用udp协议
-w 指定TCP窗口大小,默认是8KB
-B 绑定一个主机地址或接口(当主机有多个地址或接口时使用该参数)
-C 兼容旧版本(当server端和client端版本不一样时使用)
-M 设定TCP数据包的最大mtu值
-N 设定TCP不延时
-V 传输ipv6数据包

实例:
服务端

[root@localhost bin]# iperf3 -s
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------

客户端

[root@localhost iperf-3.0.5]# iperf3 -c 192.168.0.1 --reverse --parallel 4

(192.168.0.1 服务器的IP地址,可设置为推流网卡IP)
(--reverse表示服务端发送, 客户端接收;如果不加,就是客户端发送,服务端接收
--parallel 4表示4路并发流)

用法

下面是命令的用法。

单播模式

$ iperf -s
$ iperf -c <接收端主机名>或<接收端的IP地址>
  • 例1)测试TCP通信的最大速率。
$ iperf -c 192.168.1.100
  • 例2)使用TCP发送100兆字节的数据
$ iperf -c <目标地址> -l 100M
$ iperf -s -u
$ iperf -c 192.168.1.100 -u -b <传输带宽> -t <测量时间[秒] > -i <间隔>
  • 例1)以UDP方式向192.168.1.100传送60秒的10M的数据

每间隔两秒钟输出报告结果。

$ iperf -c 192.168.1.100 -u -b 10M -t 60 -i 2
  • 例2)以UDP方式向192.168.1.100传送60秒的10M的双向数据
$ iperf -c 192.168.1.100 -u -b 10M -t 60 -i 2 -d
  • 例3)以UDP方式向192.168.1.100传送60秒的10M的3路双向数据
$ iperf -c 192.168.1.100 -u -b 10M -t 60 -i 2 -P 3

组播模式

$ iperf -s -u -B <多播地址> -i <结果显示间隔>  
EX)$ iperf -s -u -B 224.0.55.55 -i 1
$ iperf -c <多播地址> -u -T < TTL > -t <测量时间[秒] > -i <间隔> -b <传输带宽> 

EX)$ iperf -c 224.0.55.55 -u -T 32 -t 10 -i 1 -b 1M

IPv6模式

$ iperf -s -V
$ iperf -c <服务器的IPv6地址> -V

 

查看结果

node2> iperf -s -u -i 1 
------------------------------------------------------------ 
Server listening on UDP port 5001 Receiving 1470 byte datagrams 
UDP buffer size: 60.0 KByte (default) 
------------------------------------------------------------ 
[ 4] local <IP Addr node2> port 5001 connected with <IP Addr node1> port 9726 
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams 
[ 4] 0.0- 1.0 sec 1.3 MBytes 10.0 Mbits/sec 0.209 ms 1/ 894 (0.11%) 
[ 4] 1.0- 2.0 sec 1.3 MBytes 10.0 Mbits/sec 0.221 ms 0/ 892 (0%) ←中间结果
[ 4] 2.0- 3.0 sec 1.3 MBytes 10.0 Mbits/sec 0.277 ms 0/ 892 (0%) 
[ 4] 3.0- 4.0 sec 1.3 MBytes 10.0 Mbits/sec 0.359 ms 0/ 893 (0%) 
[ 4] 4.0- 5.0 sec 1.3 MBytes 10.0 Mbits/sec 0.251 ms 0/ 892 (0%) 
[ 4] 5.0- 6.0 sec 1.3 MBytes 10.0 Mbits/sec 0.215 ms 0/ 892 (0%) 
[ 4] 6.0- 7.0 sec 1.3 MBytes 10.0 Mbits/sec 0.325 ms 0/ 892 (0%) 
[ 4] 7.0- 8.0 sec 1.3 MBytes 10.0 Mbits/sec 0.254 ms 0/ 892 (0%) 
[ 4] 8.0- 9.0 sec 1.3 MBytes 10.0 Mbits/sec 0.282 ms 0/ 892 (0%) 
[ 4] 0.0-10.0 sec 12.5 MBytes 10.0 Mbits/sec 0.243 ms 1/ 8922 (0.011%) ←最终结果
从左至右,测量时间,接收到的数据,bps,单向延迟,丢包数/接收数量(丢包率)
node1> iperf -c node2 -u -b 10m
------------------------------------------------------------ 

Client connecting to node2, UDP port 5001 Sending 1470 byte datagrams 
UDP buffer size: 60.0 KByte (default) 

------------------------------------------------------------ 

[ 3] local <IP Addr node1> port 9726 connected with <IP Addr node2> port 5001 
[ ID] Interval Transfer Bandwidth [ 3] 0.0-10.0 sec 12.5 MBytes 10.0 Mbits/sec 
[ 3] Sent 8922 datagrams

选项

-s

服务器模式启动

-c <服务器地址>

客户端启动模式启动

-B <绑定地址>

加入指定的组播,只在组播情况下使用

-u

UDP发送(-b 选项情况下可选)

-b <编号> [ KM ]

指定带宽(缺省为1 Mbps)仅用于UDP

-T <数>

TTL

-t <秒>

测量时间

-i <秒>

报告显示间隔

-l <字节>

数据包大小

-d

发送接收模式