How to test network speed using two Linux machines?

Introduction

This guide will show you how you can perform a network speed test using two Linux machines. It will show you the actual network bandwidth between two points in your network. We will connect a Linux machine at each point in you network and generate traffic between them. We can use simple laptops, desktops or even virtual machines for this purpose.

I will use Ubuntu 18.04, but you can use any Linux distro you like(installation command will differ for non-Debian based Linux distro). The tool used for  the bandwidth test is called iperf. This is a very simple program that needs to be installed on both machines.

Installation

Go to each of your two servers and run the following command to install iperf: sudo apt install iperf

Example:

orkhans@matrix:~$ sudo apt install iperf
[sudo] password for administrator: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  iperf
0 upgraded, 1 newly installed, 0 to remove and 217 not upgraded.
Need to get 60,4 kB of archives.
After this operation, 176 kB of additional disk space will be used.
Get:1 http://az.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 iperf amd64 2.0.10+dfsg1-1ubuntu0.18.04.1 [60,4 kB]
Fetched 60,4 kB in 0s (130 kB/s)
Selecting previously unselected package iperf.
(Reading database ... 227469 files and directories currently installed.)
Preparing to unpack .../iperf_2.0.10+dfsg1-1ubuntu0.18.04.1_amd64.deb ...
Unpacking iperf (2.0.10+dfsg1-1ubuntu0.18.04.1) ...
Setting up iperf (2.0.10+dfsg1-1ubuntu0.18.04.1) ...
Processing triggers for man-db (2.8.3-2) ...

 

Basic speed test

To make a speed test we need to do two things:

  1. Run iperf on any machine in a server mode
  2. Run iperf on another machine in a client mode and connect to the server

Step 1.

Go to the first Linux box and run the following command:

orkhans@Linux1:~$ iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------

You can see that our Linux machine is running iperf in a server mode (-s option) which is listening at port TCP 5001.

 

Step 2.

Go to the second Linux machine and run the following command iperf -c SERVER_IP, where SERVER_IP is the IP address of the first Linux box, running iperf in a server mode:

orkhans@Linux2:~$ iperf -c 192.168.37.79
------------------------------------------------------------
Client connecting to 192.168.37.79, TCP port 5001
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 192.168.37.76 port 55268 connected with 192.168.37.79 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  9.09 GBytes  7.81 Gbits/sec

This command instructs iperf to connect (-c option) to the first machine, running iperf server( in my case it is 192.168.37.79).

The output says that we connect to server’s port TCP 5001 and then it performs a speed test during 10 seconds and shows us the result. In my case the bandwidth between two machines was 7.81 Gbits/sec.

iperf options

We have used iperf with default settings, which are working pretty well, but you can also use different options some of which are:

-t – time in seconds to transmit for (default is 10 seconds). Specified on a client

-p – server port to listen on/connect to.

-w – TCP window size

You can find the full list of options on a man page for iperf.

 

Conclusion

As you can see, iperf tool is a flexible and still easy to use.

Thank you for reading.

Tags:,

Add a Comment