Skip to content

Instantly share code, notes, and snippets.

@jg3
Last active February 11, 2025 14:52
Show Gist options
  • Save jg3/e65e79e2907f49612453ce36df19d433 to your computer and use it in GitHub Desktop.
Save jg3/e65e79e2907f49612453ce36df19d433 to your computer and use it in GitHub Desktop.
Notes on using iperf3
title
iperf3 notes

Notes on iperf3

iperf3: https://software.es.net/iperf/

Current version as of these notes: 3.18

Server

A FreeBSD jail runs iperf3 as a server so there is a consistent target to test against.

Server startup, including command line string.

This is all basic FreeBSD stuff. The actual server command is:
/usr/local/bin/iperf3 -s -D --idle-timeout 60 --logfile /var/log/iperf3.log

Here is how that gets wrapped into /usr/local/etc/rc.d/iperf3:

#!/bin/sh
#
# PROVIDE: iperf3
# REQUIRE: NETWORKING
# KEYWORD: shutdown
# SEE ALSO: https://gist.github.com/jg3/e65e79e2907f49612453ce36df19d433

. /etc/rc.subr

name="iperf3"
rcvar="iperf3_enable"

command="/usr/local/bin/iperf3"
command_args="-s -D --idle-timeout 60 --logfile /var/log/iperf3.log"
pidfile="/var/run/${name}.pid"

start_cmd="${name}_start"
stop_cmd="${name}_stop"

iperf3_start() {
    echo "Starting ${name}..."
    ${command} ${command_args}
    sleep 1  # Allow time for the daemon to start
    pgrep -x iperf3 > ${pidfile}  # Capture the PID of the iperf3 process
}

iperf3_stop() {
    echo "Stopping ${name}..."
    if [ -f ${pidfile} ]; then
        kill "$(cat ${pidfile})" && rm -f ${pidfile}
    else
        echo "${name} is not running (no pidfile found)."
    fi
}

load_rc_config $name
: ${iperf3_enable:=NO}

run_rc_command "$1"

And to kick that off at boot there's a line in in /etc/rc.conf there is a line:
iperf3_enable=YES

Also note that the server is logging output to /var/log/iperf3.log, which could eventually fill up your disk, so use newsyslog (again, more FreeBSD basics) to rotate that log. Adding the following line to /etc/newsyslog.conf will rotate the log every day at midnight and keep the last seven days of logs:

/var/log/iperf3.log    root:wheel    644  7     *    @T00   Z /var/run/iperf3.pid

And now, if you want to monitor what's happening on the server you can tail -F /var/log/iperf3.log

Clients

This is a collection of client invocations for iperf3 I liked for one reason or another:

One Gigabyte each way

iperf3 -c deathray.org --bytes 1024M --bidir

10 MB each way, repeat every 10s

Wrapping this one with watch runs it each time ... just make sure the -n <seconds> you give to watch is longer than the transfer will take.
watch -n 10 "iperf3 -c deathray.org --bytes 10M --bidir"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment