IPERF 网络性能测试

Iperf 是一个网络性能测试工具。Iperf可以测试最大TCP和UDP带宽性能。Iperf具有多种参数和UDP特性,可以根据需要调整。Iperf可以报告带宽,延迟抖动和数据包丢失。

Iperf 参数选项

#介绍参考链接:https://iperf.fr/iperf-doc.php

iperf服务器端选项

-s 以server模式启动 eg:*iperf –s* 。Server端为数据的接收端。
-D 以服务方式运行ipserf
-R 停止iperf服务,针对-D 
-o <filename>  重定向输出报告或错误信息到指定文件。
-c <hostname/IP> 如果Iperf运行为服务器模式,则可利用-c参数指定一个客户端,本机将接受指定客户端的连接,但不支持UDP协议。
-P,--parallel #  设置Iperf服务模式下的最大连接数,默认值为0,表示不限制连接数量。

iperf客户端选项

-b,--bandwidth 指定客户端通过UDP协议发送信息的带宽,默认值为1Mbit/s
-c,--client <hostname/IP> 指定Iperf服务器的主机名和IP地址
-d,--dualtest 同时进行双向传输测试
-n,--num 指定传输的字节数
-r,--tradeoff 单独进行双向传输测试
-t,--time 指定Iperf测试时间,默认10秒
-L,--listenport 指定一个端口,服务器将利用这个端口与客户机连接
-P, --parallel 设置Iperf客户端至Iperf服务器的连接数,默认值为1
-S, --tos  设置发出包的类型,具体类型请参阅man文档
-F 指定需要传输的文件
-T 指定ttl值

通用参数

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

软件安装

[root@xiesshavip001 ~]# yum install https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm -y
[root@xiesshavip001 ~]# yum install iperf -y  # 注:yum安装的iperf是2版本,如果需要安装3版本,可以到官网下载源包安装

Iperf 网络测试

  1. iperf -s 命令启动server:
[root@xiesshavip002 ~]# iperf -s
------------------------------------------------------------
Server listening on TCP port 5001      # 默认端口为5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
  1. 向IP为192.168.130.20的主机发出TCP测试,,测试时间为20秒,并每2秒返回一次测试结果
[root@xiesshavip001 ~]# iperf -c 192.168.130.20 -i 2 -t 20
  1. 测试双向传输
[root@xiesshavip001 ~]# iperf -c 192.168.130.20 -i 2 -t 20 -d
  1. 指定传输字节数
[root@xiesshavip001 ~]# iperf -c 192.168.130.20 -i 2 -t 20 -d -n 10240
  1. 设置TCP传输窗口
[root@xiesshavip001 ~]# iperf -c 192.168.130.20 -i 2 -t 20 -d -n 10240 -w 300k 
# 注:窗口大小不能超过默认的TCP window size:  416 KByte。并且服务端要与客户端的传输窗口大小一致
  1. 指定端口传输
[root@xiesshavip001 ~]# iperf -c 192.168.130.20 -i 2 -t 20 -d -p 12345
  1. 使用UDP测试
[root@xiesshavip001 ~]# iperf -c 192.168.130.20 -i 2 -t 20 -d -u

iperf --help

[root@xiesshavip001 ~]# iperf --help
Usage: iperf [-s|-c host] [options]
       iperf [-h|--help] [-v|--version]

Client/Server:
  -b, --bandwidth #[KMG | pps]  bandwidth to send at in bits/sec or packets per second
  -f, --format    [kmKM]   format to report: Kbits, Mbits, KBytes, MBytes
  -i, --interval  #        seconds between periodic bandwidth reports
  -l, --len       #[KM]    length of buffer to read or write (default 8 KB)
  -m, --print_mss          print TCP maximum segment size (MTU - TCP/IP header)
  -o, --output    <filename> output the report or error message to this specified file
  -p, --port      #        server port to listen on/connect to
  -u, --udp                use UDP rather than TCP
  -w, --window    #[KM]    TCP window size (socket buffer size)
  -z, --realtime           request realtime scheduler
  -B, --bind      <host>   bind to <host>, an interface or multicast address
  -C, --compatibility      for use with older versions does not sent extra msgs
  -M, --mss       #        set TCP maximum segment size (MTU - 40 bytes)
  -N, --nodelay            set TCP no delay, disabling Nagle's Algorithm
  -V, --IPv6Version        Set the domain to IPv6

Server specific:
  -s, --server             run in server mode
  -U, --single_udp         run in single threaded UDP mode
  -D, --daemon             run the server as a daemon

Client specific:
  -c, --client    <host>   run in client mode, connecting to <host>
  -d, --dualtest           Do a bidirectional test simultaneously
  -n, --num       #[KM]    number of bytes to transmit (instead of -t)
  -r, --tradeoff           Do a bidirectional test individually
  -t, --time      #        time in seconds to transmit for (default 10 secs)
  -B, --bind [<ip> | <ip:port>] bind src addr(s) from which to originate traffic
  -F, --fileinput <name>   input the data to be transmitted from a file
  -I, --stdin              input the data to be transmitted from stdin
  -L, --listenport #       port to receive bidirectional tests back on
  -P, --parallel  #        number of parallel client threads to run
  -T, --ttl       #        time-to-live, for multicast (default 1)
  -Z, --linux-congestion <algo>  set TCP congestion control algorithm (Linux only)

Miscellaneous:
  -x, --reportexclude [CDMSV]   exclude C(connection) D(data) M(multicast) S(settings) V(server) reports
  -y, --reportstyle C      report as a Comma-Separated Values
  -h, --help               print this message and quit
  -v, --version            print version information and quit

[KM] Indicates options that support a K or M suffix for kilo- or mega-

The TCP window size option can be set by the environment variable
TCP_WINDOW_SIZE. Most other options can be set by an environment variable
IPERF_<long option name>, such as IPERF_BANDWIDTH.

Source at <http://sourceforge.net/projects/iperf2/>
Report bugs to <iperf-users@lists.sourceforge.net>
[root@xiesshavip001 ~]#
原文地址:https://www.cnblogs.com/xieshengsen/p/6505098.html