Testing Network Speed Between Two Linux Servers

Table of Contents

Introduction

When managing a network infrastructure, it’s crucial to ensure optimal performance between servers. One key aspect of performance is the network speed between two Linux servers. This article will guide you through the process of testing the network speed between two Linux servers, providing step-by-step instructions and relevant code snippets.

Prerequisites

Before we begin, ensure the following prerequisites are met:

  1. Two Linux Servers: Ensure that you have two Linux servers with network connectivity. This guide assumes you have basic knowledge of Linux terminal commands.
  2. iperf Installation: Install iperf on both servers. Iperf is a widely used tool for measuring TCP and UDP performance. Install it using the package manager specific to your Linux distribution:
   # For Ubuntu/Debian
   sudo apt-get install iperf

   # For CentOS/RHEL
   sudo yum install iperf

Testing Network Speed Using iperf

Step 1: Start iperf Server on one machine

On the server where you want to measure the incoming speed, run the following command:

iperf -s

This starts the iperf server, waiting for connections.

Step 2: Run iperf Client on the other machine

On the server where you want to measure the outgoing speed, run the following command:

iperf -c <server_ip>

Replace <server_ip> with the IP address or hostname of the server where the iperf server is running.

Step 3: Analyze Results

After the test completes, you’ll see the results on both the client and server terminals. Look for the “Throughput” or “Bandwidth” section to find the network speed in megabits per second (Mbps) or another unit of your choice.

Testing Network Speed Using Speedtest-cli

Step 1: Install speedtest-cli

Install speedtest-cli using your package manager:

# For Ubuntu/Debian
sudo apt-get install speedtest-cli

# For CentOS/RHEL
sudo yum install speedtest-cli

Step 2: Run Speed Test

Run the following command to test the network speed:

speedtest-cli

This will connect to a speedtest.net server, upload and download a small amount of data, and then provide the results, including the upload and download speeds.

In addition to using specialized tools like iperf and speedtest-cli, you can also leverage the power of netcat (nc) for a simple yet effective network speed test. Netcat allows you to create custom connections and transfer data between servers.

Step 1: Install netcat

Ensure that netcat is installed on both servers:

# For Ubuntu/Debian
sudo apt-get install netcat

# For CentOS/RHEL
sudo yum install nc

Step 2: Start netcat Receiver (Server)

On the server where you want to measure incoming speed, run the following command:

nc -l -p 5000 > /dev/null

This starts a netcat server listening on port 5000.

Step 3: Run netcat Sender (Client)

On the server where you want to measure outgoing speed, run the following command:

dd if=/dev/zero bs=1M count=100 | nc <server_ip> 5000

Replace <server_ip> with the IP address or hostname of the server where the netcat server is running. This command sends 100MB of zero data to the server.

Step 4: Analyze Results

After the transfer is complete, you can calculate the speed by dividing the data size by the transfer time. This provides you with the transfer rate in megabits per second (Mbps) or another unit of your choice.

# Example calculation for 100MB transfer
data_size=100  # in megabytes
transfer_time=10  # in seconds

speed=$(echo "scale=2; $data_size / $transfer_time" | bc)
echo "Transfer Speed: $speed Mbps"

Conclusion

In this article, we explored multiple methods for testing network speed between two Linux servers. Whether you choose iperf for its detailed performance metrics, speedtest-cli for a quick and user-friendly experience, or netcat for a more custom approach, regular testing is vital for maintaining a robust and efficient network infrastructure.

Consider incorporating these tests into your network monitoring and maintenance routines. Regular assessments empower you to identify potential issues early, optimize your network configuration, and ensure that your servers deliver optimal performance for your applications and users.

Undefined vs Null in JavaScript

Undefined vs Null in JavaScript

JavaScript, as a dynamically-typed language, provides two distinct primitive values to represent the absence of a meaningful value: undefined and null. Although they might seem

Read More »