1. Introduction

Efficient data transfer between Linux servers is an important aspect of maintaining a responsive network infrastructure. The speed at which data can be transmitted between servers directly impacts the overall performance of applications and services. For example, features like TCP traffic control can affect the data exchange speeds.

In this tutorial, we’ll explore various tools and methodologies designed to measure the efficiency of data transfer. The goal is to equip users and administrators with the knowledge needed to effectively test network speed between Linux servers.

Notably, if we have a firewall running on the servers, we need to ensure that connections are allowed on the port used. Importantly, we focus solely on working with IP for network testing, and we don’t cover other networking protocols or configurations.

2. Using iperf

iperf is a tool for measuring the maximum TCP and UDP bandwidth performance over IP. Hence, it helps to identify the network’s throughput capacity by generating traffic and measuring the data transfer rates between systems.

2.1. Installing iperf

First, let’s install iperf via apt-get and sudo:

$ sudo apt-get install iperf

Once it’s installed, we can start the test.

2.2. TCP Bandwidth Testing

iperf provides a measure of the maximum TCP bandwidth performance.

First, on one of the servers, we set it up as the server by running iperf in server mode:

$ iperf -s

Here, we used -s for initiating iperf in server mode to be ready for accepting incoming connections.

At this point, on the other server, let’s run iperf in client mode:

$ iperf -c 10.211.55.5
------------------------------------------------------------
Client connecting to 10.211.55.5, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[  1] local 10.211.55.4 port 56200 connected with 10.211.55.5 port 5001 (icwnd/mss/irtt=14/1448/1545)
[ ID] Interval       Transfer     Bandwidth
[  1] 0.00-10.03 sec  4.17 GBytes  3.57 Gbits/sec

In this case, we used -c for initiating iperf in client mode to connect to the server with the IP address 10.211.55.5.

The first part of the output indicates that the client is connecting to the server with the IP address 10.211.55.5 using the TCP protocol on port 5001.

The second part shows that, during the 10.03 seconds test interval, the client transferred 4.17 GB of data to the server at an average bandwidth of 3.57 Gbits per second.

Alternatively, we can change the default port:

# Server
$ iperf -s -p 8080

# Client
$ iperf -c 10.211.55.5 -p 8080

In this instance, we changed the default port to port 8080 by using the -p option on both ends.

2.3. UDP Bandwidth Testing

iperf also supports UDP testing:

# Server
$ iperf -s -u

# Client
$ iperf -c 10.211.55.4 -u

As we can see, we can use the -u flag on both the server and client sides.

2.4. Parallel Testing and Optimization

This time, we can maximize the efficiency of bandwidth testing:

$ iperf -c 10.211.55.4 -P 20 -t 30
------------------------------------------------------------
Client connecting to 10.211.55.4, TCP port 5001
TCP window size: 85.0 KByte (default)
------------------------------------------------------------
[  3] local 10.211.55.5 port 40904 connected with 10.211.55.4 port 5001
[  4] local 10.211.55.5 port 40936 connected with 10.211.55.4 port 5001
[ 10] local 10.211.55.5 port 40950 connected with 10.211.55.4 port 5001
...
[ ID] Interval       Transfer     Bandwidth
...
[ 14] 0.0000-30.1182 sec   552 MBytes   154 Mbits/sec
[  4] 0.0000-30.1220 sec   727 MBytes   202 Mbits/sec
[SUM] 0.0000-30.0672 sec  10.4 GBytes  2.97 Gbits/sec
[ CT] final connect times (min/avg/max/stdev) = 1.346/4.642/14.595/3.670 ms (tot/err) = 20/0

In this case, we used -P to specify that the test should use 20 parallel client threads to send data to the server simultaneously. Moreover, the -t option is used to set the duration of the test which is 30 seconds.

As a result, this iperf command provides detailed information about each connection’s performance and a comprehensive summary of the test results.

3. Using nc and dd

To evaluate network speed between two Linux servers, we can use a combination of nc and dd.

In particular, to initiate the data transfer, we employ nc, which facilitates efficient communication between the servers. Additionally, we utilize dd to generate and manage the data flow, ensuring a comprehensive evaluation of network performance.

First, let’s install nc on both servers:

$ sudo apt-get install netcat

Once it’s installed, we start nc in listening mode on the server where we want to receive data:

$ nc -vvlnp 5001 > /dev/null
Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: Listening on :::5001
Ncat: Listening on 0.0.0.0:5001
Ncat: Connection from 10.211.55.5.

Let’s break down the command:

  • -vv is verbose mode, providing more detailed output
  • -l means listen mode, instructing nc to wait for an incoming connection
  • -n forces numeric-only IP addresses, disables DNS resolution
  • -p 5001 is the port number to listen on
  • > /dev/null redirects output to /dev/null to discard any received data

Then, we use the combination of nc and dd on the other server:

$ dd if=/dev/zero bs=1M count=1K | nc -vvn 10.211.55.4 5001
Connection to 10.211.55.4 5001 port [tcp/*] succeeded!
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 5.40932 s, 198 MB/s

Let’s dissect the first part of the command:

  • if=/dev/zero specifies the input file as /dev/zero, producing an endless stream of null bytes
  • bs=1M sets the block size to 1 MB
  • count=1000 specifies the number of blocks to copy, creating a 1-GB file

Finally, we use | nc 10.211.55.4 5001 to pipe the output of dd to nc and send the data to the server at IP address 10.211.55.4 on port 5001.

In summary, we transferred data between these two servers, achieving a speed of approximately 198 MB/s in the examination.

4. Using SSH and dd

Of course, SSH can provide a secure channel for data transmission, and dd enables measurement of the data transfer rate.

Let’s see how we can test network speed:

$ dd if=/dev/zero bs=1M count=1000 | ssh [email protected] 'dd of=/dev/null'
1000+0 records in
1000+0 records out
1048576000 bytes transferred in 4.441908 secs (236064322 bytes/sec)
2048000+0 records in
2048000+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 4.52663 s, 232 MB/s

Let’s understand each part before the pipe:

  • if=/dev/zero specifies the input file as /dev/zero, which generates an endless stream of zeros
  • bs=1M sets the block size to 1 megabyte
  • count=1000 specifies the number of blocks to be transferred, creating a 1GB file

We pipe the results through and SSH tunnel after a pipe with ssh [email protected]. Critically, dd of=/dev/null on the remote server writes the incoming data to /dev/null, effectively discarding it.

The results indicate the network speed between the local and remote servers. In this case, the average speed is approximately 232 MB/s, providing insights into the performance of the network connection for data transfer between these two Linux servers.

5. Using nuttcp

nuttcp is a network performance measurement tool that is commonly used for testing network speed and throughput between two systems. Hence, it enables us to assess the performance of a network connection by measuring the amount of data transferred over time, particularly with TCP.

First, let’s install nuttcp on both servers:

$ sudo apt-get install nuttcp

Then, we start nuttcp in receive mode on one of the servers:

$ nuttcp -r

This command tells nuttcp to wait for incoming connections and measure the throughput.

At this point, we start nuttcp in send mode on the other server:

$ nuttcp 10.211.55.4
 7301.4253 MB /  10.84 sec = 5652.0274 Mbps 31 %TX 48 %RX 0 retrans 0.98 msRTT

In this case, we measured the network performance between the client and the server. As a result, the test involved transmitting approximately 7301.4253 MB of data over a duration of 10.84 seconds. Subsequently, the calculated throughput during this test was approximately 5652.0274 Mbps.

6. Conclusion

In this article, we delved into a variety of tools and methodologies tailored for the precise evaluation of network speeds.

From iperf for TCP and UDP bandwidth measurement to the combination of nc and dd, and secure SSH with dd, we explored diverse approaches.

In conclusion, we got some insights into the intricacies of network speed testing and responsiveness of data exchange within Linux server environments.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.