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
pkg install -y iperf3
Step 2: Create an rc.d script
mkdir -p /usr/local/etc/rc.d/
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"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
load_rc_config $name
: ${iperf3_enable:="NO"}
iperf3_start()
{
echo "Starting ${name}..."
/usr/local/bin/iperf3 -s -D
echo $(pgrep -fx "/usr/local/bin/iperf3 -s -D") > ${pidfile}
}
iperf3_stop()
{
echo "Stopping ${name}..."
if [ -f "${pidfile}" ]; then
kill $(cat ${pidfile}) && rm -f ${pidfile}
else
pkill -fx "/usr/local/bin/iperf3 -s -D"
fi
}
run_rc_command "$1"
# PROVIDE: iperf3
# REQUIRE: NETWORKING
# KEYWORD: shutdown
. /etc/rc.subr
name="iperf3"
rcvar=iperf3_enable
command="/usr/local/bin/iperf3"
pidfile="/var/run/${name}.pid"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
load_rc_config $name
: ${iperf3_enable:="NO"}
iperf3_start()
{
echo "Starting ${name}..."
/usr/local/bin/iperf3 -s -D
echo $(pgrep -fx "/usr/local/bin/iperf3 -s -D") > ${pidfile}
}
iperf3_stop()
{
echo "Stopping ${name}..."
if [ -f "${pidfile}" ]; then
kill $(cat ${pidfile}) && rm -f ${pidfile}
else
pkill -fx "/usr/local/bin/iperf3 -s -D"
fi
}
run_rc_command "$1"
EOF
Step 3: Make it executable
chmod +x /usr/local/etc/rc.d/iperf3
Step 4: Enable and start the service
sysrc iperf3_enable="YES"
service iperf3 start
Step 5: Verify it’s running
service iperf3 status
Step 6: Verify it's working
# Test download locally
iperf3 -R -c localhost
# Test upload remotely
iperf3 -c localhost
# Test download from remote address
iperf3 -R -c [IP-ADDRESS]
# Test upload from remote address
iperf3 -c [IP-ADDRESS]
No comments:
Post a Comment