Iperf is a very useful utility for network troubleshooting. In this post I’ll share my list of Iperf commands that I have found useful.
What is Iperf?
Iperf is a network performance utility that can generate both TCP and UDP traffic for testing bandwidth, latency, and packet loss. Iperf is very powerful and can easily generate enough traffic to saturate a 1Gb, or 10Gb connection. Iperf is included with most Linux distributions but you can compile Iperf for windows if needed.
In order to use Iperf you’ll need to setup an Iperf server, Iperf clients can then connect to the server in order to run tests. By default Iperf is uni-directional and sends data from the client to the server.
In my examples I’m using 192.168.1.1 as the address of my Iperf server.
Running iperf -s will setup a basic Iperf server, you can also run Iperf in daemon mode by running iperf -D.
Basic TCP Unicast Test
The simplest test you can do with Iperf is a basic TCP test. By default the server will use a TCP window size of 85.3KB. The client will connect to the server on port 5001 using a TCP window size of 16KB. The -t option instructs the client to run the test for 30 seconds instead of the default of 10 seconds.
[Server] – iperf -s -i 1
[Client] – iperf -c 192.168.1.1 -t 30
Parallel TCP connections
Parallel connections can be useful if you need to saturate the bandwidth of a link. The bandwidth of a single TCP session can be greatly affected by the size of the receive window and the latency of the link.
To enable parallel connections add the -P flag to the Iperf client parameters followed by the number of connections you want. Make sure to use a capital P, lowercase p will specify a different port number to connect on.
[Server] – iperf -s -i 1
[Client] – iperf -c 192.168.1.1 -t 30 -P 10
UDP Mode
Testing with UDP packets requires the -u flag on both the client and server. The cool thing about UDP mode is that you don’t have to use a server. Instead you can use the interface counters on your switches. You can also specify the destination address to be a multicast group, the default TTL for multicast is 1 (be careful). To set a different TTL use the -T option on the client.
If you want to test for jitter and packet loss then you should use UDP mode.
[Server] – iperf -s -i 1
[Client] – iperf -c 192.168.1.1 -t 30 -u
In UDP mode iperf defaults to 1Mb/s, you can tell it to use more bandwidth by using the -b flag followed by the number of bits/sec to send. For example, iperf -c 192.168.1.1 -u -b 100000000 would send at a rate of 100Mb/s.
Bidirectional testing
If you want to test throughput both to and from the server at the same time you can use the -d option to run a bidirectional test. This will send data to the server, and receive data from the server simultaneously.
[Server] – iperf -s -i 1
[Client] – iperf -c 192.168.1.1 -t 30 -d
Bandwidth limiting
If you need to test for packet loss or other problems at a specific rate of bandwidth you can use the -b flag to specify the maximum throughput in bits/second.
[Server] – iperf -s -i 1
[Client] – iperf -c 192.168.1.1 -t 30 -b 100000
Transfer 1GB of data then stop
Instead of running the test for a specific period of you can instruct Iperf to stop running after trasfering a certain amound of data. The example below will send 1GB (1024³) of data to the server and then stop
[Server] – iperf -s -i 1
[Client] – iperf -c 192.168.1.1 -n 1073741824
Stop the iPerf server
To kill the iperf server just press CTRL+C in your terminal and it will interrupt the process.
If you are running iPerf in daemon mode you’ll need to find the process ID first
ps -ef | grep iperf
root 16186 1 0 22:00 ? 00:00:00 iperf -s -D
Then kill it
kill 16186
Useful References
Energy Sciences Network Host Tuning Guide
Using Iperf – Guide by Jon Dugan
Thanks for the effort of the 2 iperf blogs. I will spend some time reading and testing them out. 🙂
Thanks for your comment! I hope that you find iperf to be as useful of a tool as I have.
hi my name raj i having a problem with iperf….actualy i using 10gb copper cable to testing that bandwidth but i cannot get…if i type 100m i get 100mb bandwidth but when i type 10000 i get 562mb bandwidth it wont go more than that so can u help me…..i trying this two days but still like that….tq
I have ran parallel TCP streams to saturate my switch. How can I find if the switch is saturated or not?
If you have a managed switch you can check the interface counters to view the port utilization and also check for queue drops.
For example on Cisco switches you can run show interface X, replacing x with the port in question (Gi1/1, etc). You can also run ‘show interface counters errors’ to get a summary of errors and output discards across the switch. Turning on Netflow (if supported) can provide some great real time data on switch utilization.
If you’re not running Cisco equipment but you still have a managed switch then check the documentation for your specific model to see what commands are available.
i am getting “Connect failed : Connection timeout” message as error in client side. i am giving simple server side cmd as “iperf -s ” and client cmd as “iperf -c ” .
i am using 2 PCs for this connection
can anybody help me how i can make it to connect plz?