Search code examples
linuxubuntuapache2iperf

How to configure ports on apache server for iperf3


I'm using my apache server for running TCP and UDP traffic using iperf3. I manually execute a command on my server to listen to a port.

~# iperf3 -i 5 -s -p 7759
-----------------------------------------------------------
Server listening on 7759
-----------------------------------------------------------

I'm wondering if there is a way to configure my apache server to have few ports (say 7760,7761,7762,...7770) permanently open on my apache server for iperf traffic so that I don't have to manually execute the aforementioned command to open the port for iperf traffic


Solution

  • The answer depends on the definition of permanently open.

    If ports remaining open after you log out from your webserver is sufficiently good approximation of permanently open. Then all you need is start iperf with nohup command.

         nohup iperf3 -s -p 7759 >/tmp/log 2>&1 
    

    See this question for more details on keeping backround processes after the shell that spawned them terminates. In particular, check out the answers that suggest using the screen command.

    If you need iperf server to keep the ports open between reboots you need to configure the init process to spawn iperf3 at boot up time. For this you need root access to your webserver.

    As root you could add the following lines to /etc/rc.local file

    iperf3 -s -p 7759 > /tmp/iperf-7759.log 2>&1 &
    iperf3 -s -p 7760 > /tmp/iperf-7760.log 2>&1 &
    ... 
    iperf3 -s -p 7760 > /tmp/iperf-7770.log 2>&1 &
    

    See also this question on how to ensure a command is run every time the machine starts.