7
September
2021
16:02

Testing data transfer speed using SSH and iPerf

7 September 2021 16:02

An easy way to check the speed of the Internet or local network is using the iPerf command.

Introduction

There are three speed testing programs in Linux - iPerf (port 5001) and iPerf3 (port 5201).
The article discusses the first iPerf program, but with the same success you can apply the instructions to the iPerf3 program, replacing port number 5001 with 5201.

Action plan

  1. Set up a firewall on the server by adding an allowing rule for the iPerf server
  2. Configure port forwarding (for local network we skip)
  3. Install iperf on the client
  4. Connect to the server via SSH
  5. Start iperf server
  6. Perform a data transfer speed test from the client

Step 1. Allow port 5001 for speed testing

We configure the firewall on the server:

sudo ufw allow 5001

where 5001 is the default port for the iPerf service.

Step 2. Port forwarding

For a local network or VPN, I skip the forwarding point to port 5001.

For the Internet, you need to open and forward 2 secret ports on the router:
1) to control a PC via SSH (forwarding to server port 22) - port number 22334.
2) for speed testing (forwarding to port 5001 of the iPerf server by default) - port number 12345.

Step 3. Installing iPerf client/server

On a desktop computer - an Ubuntu Linux server and on a client - a netbook running MX Linux) I ran the same command:

sudo apt-get install iperf

Step 4. Connect via SSH to the server

On the local network:

ssh user@192.168.1.8 -p 22334

If from outside:

ssh user@123.45.67.89 -p 22334

where: user is the user name on the server, 123.45.67.8 is replaced with the IP address of the SSH server on the Internet (“white” IP address), 22334 is the secret port for management via SSH.

I entered the password and got into the server console.

Step 5. Launch the iPerf server

Through an SSH session on the server, I launched the program with the "-s" key

iperf -s

I left the ssh session running. The server IP address on the local network is static - 192.168.1.8.

Step 6. Testing data transfer speed using iPerf within the local network

Launched another instance (window) of the terminal on the client.

On a client on the local network I ran the following command:

iperf -c 192.168.1.8 -n 10M

Where 192.168.1.8 is the IP address of the server on the local network, 10M is the size of the data packet for measuring speed,
and the default port is 5001.

Or, if iperf3 is used, the command is:

iperf3 -c 192.168.1.8 -n 10M

Result:

$ iperf -c 192.168.1.8 -n 10M

Client connecting to 192.168.1.8 TCP port 5001

TCP window size: 110 KByte (default)

------------------------------------------------

[ 1] local 192.168.1.101 port 49772 connected with 192.168.1.8 port 5001

[ ID] Interval Transfer Bandwidth

[ 1] 0.0000-1.1685 sec 10.0 MBytes 71.8 Mbits/sec

Step 7. Measuring speed from outside the local network using iPerf

The server side remains the same:

iperf -s

Client part: calling a command with a “white” IP address (123.45.67.8) and the “-p” key - the port number forwarded to the iPerf server.

iperf -c 123.45.67.8 -p 12345  -n 10M

Result:

Learned how to measure speed between two points.

In the future, because The setup is complete, only steps 4, 5 and 7 can be performed to measure the speed.

Differences between iperf and iperf3

The programs were written at different times.
iperf3 is the more recent port of the first 5001, and the latest iperf3 is port 5201.

iperf3 as a service

iPerf3 in systemd (the service initialization and management subsystem in Linux) can be started as a service:

systemctl enable --now operf3.service

After executing the specified command, the specified iperf3 service will be enabled and immediately started.
You can find out the status of a service using the command

systemctl status iperf3.service

As mentioned above, the external port for connecting via the iperf3 protocol is 5201/TCP.
If the iperf3.service service is running, the "iperf3 -s" command to start the iperf3 server does not need to be executed, since the computer with the iperf3.service service running always responds to requests to port 5201 when executing the command from another client computer iperf3 -c ip_адрес_сервера -n 10M.

Last change: 08/21/2022



Related publications