Saturday, October 25, 2025

How to run iperf as a service

On my FreeBSD routers I wan to run iperf as an always running service (daemon). The reason is to have possibility to test network throughput anytime I need it. Here is the rc script to do so.

Step 1: Create an rc.d script

cat > /usr/local/etc/rc.d/iperf3 <<EOF  
#!/bin/sh

# PROVIDE: iperf3
# REQUIRE: NETWORKING
# KEYWORD: shutdown

. /etc/rc.subr

name="iperf3"
rcvar=iperf3_enable
command="/usr/local/bin/iperf3"
pidfile="/var/run/${name}.pid"
command_args="-s -D -I ${pidfile}"

load_rc_config $name
: ${iperf3_enable:="NO"}

run_rc_command "$1"
EOF

 

Step 2: Make it executable

chmod +x /usr/local/etc/rc.d/iperf3

Step 3: Enable and start the service

sysrc iperf3_enable="YES" 

Step 4: Verify it’s running 

service iperf3 status

Step 5: Verify it's working

 
# Test download locally 
iperf3 -R -c localhost 
# Test upload remotely 
iperf3 -c localhost 
 
# Test download locally
iperf3 -R -c [IP-ADDRESS]
# Test upload remotely
iperf3 -c [IP-ADDRESS]

No comments:

Post a Comment