How to Fix Bugs on a Permanent iPerf Server

Recently I discovered a bug in iPerf. iPerf is a very useful tool to test and measure bandwidth performance between an iPerf server and a client. In most cases, you run the bandwidth test only once between the two. The other option is to set up an iPerf server to run permanently on a host and then target that host to get iPerf measurements from several locations or hosts, which is more convenient because you don’t have to manage two hosts each time you want to run a test. But here is where the problems start…

This works as follows: On one machine, we run the command iperf -s -D This starts the iPerf server (option -s) and puts it in daemon mode (option -D), which means the server will keep running even if we logout of the machine. Then, we run iperf -c [IP of iperf server] from another machine.

The first time I tried this, it worked well initially, i.e., multiple iPerf tests could run by using the same iPerf server running as daemon. I noticed that after a day or two, the iPerf server wouldn’t respond and error messages (even a segmentation fault) appeared on the iPerf client side. By checking the processes on the iPerf server, it appeared that the process iperf -s -D was running on the host, but it wouldn’t accept any traffic. If I killed and restarted the iPerf server process, it would run for a day or two until it crashed again.

To overcome this problem, I wrote this script to restart the process:



for i in {1..10}; do
    pid=$(ps ax | grep "iperf -s -D" | grep -v grep | awk '{print $1;}')
    if [ "$pid" == "" ]; then
        echo "$0: iperf process not found. Starting iperf"
        iperf -s -D
        exit 0

    established=$(netstat -tunap | grep $pid/ipe | grep -q ESTABLISHED)
    if [ "$?" == "0" ]; then
        echo "$0: iperf pid $pid established. Not restarting iperf process"
        echo "$0: killing iperf server with pid: $pid"
        kill -9 $pid
        echo "$0: Restarting iperf server and exiting"
        iperf -s -D
    sleep 30

exit 0

Save this script in the file /home/panos/ and make it executable with chmod +x /home/panos/ Finally run the test every hour on the 25th minute by saving the following file in /etc/cron.d/restart_iperf_cron

25 * * * * root /home/panos/

When the script runs, it first checks if the iPerf daemon is running. If not, it starts the daemon and exits. If it’s running, it kills the existing process and restarts a new one. In addition, it checks whether there is an established iPerf test connection, and makes sure that it doesn’t interrupt it.

This is a bug in iPerf version 2 that I’m sure others have come across and wondered why their tests were failing. I haven’t noticed the same problem with iPerf version 3. Although iPerf version 2 is older, it is much more widespread, and until everybody switches to version 3, this script might be helpful.

decoration image

Get your free trial now

Monitor your network from the user perspective

You can share

Twitter Linkedin Facebook

Let's keep in touch

decoration image