Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: December 15, 2023
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.
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.
First, let’s install iperf via apt-get and sudo:
$ sudo apt-get install iperf
Once it’s installed, we can start the test.
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.
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.
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.
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:
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:
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.
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:
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.
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.
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.