In the world of networking, ensuring your applications perform seamlessly under various network conditions is paramount. To achieve this, tools like netem and iperf3 come to the rescue, enabling you to simulate and test different network scenarios right from your own development environment.

Emulating Network Conditions with netem

netem is a Linux kernel module that enables you to introduce controlled network impairments. With netem, you can replicate real-world network challenges in a controlled environment. This tool allows you to emulate Latency, Packet Loss, Limit Bandwidth, Duplicate Packets and more (for more information go to the Netem man page.)

The netem module is usually built into the Linux kernel, so no separate installation is required. You’ll need to use the tc (traffic control) command to manipulate network traffic. For instance, you can emulate different network conditions like latency and packet loss, below we can see some examples of the use of netem:

# To add latency
sudo tc qdisc add dev eth0 root netem delay <delay_in_ms>

# To introduce packet los
sudo tc qdisc add dev eth0 root netem loss <loss_percentage>%

# To limit the bandwidth
sudo tc qdisc add dev eth0 root tbf rate <rate>mbit burst <burst_size> latency <latency_in_ms>

# Remember change eth0 with the name of your NIC

Measuring Performance with iperf3

While netem lets us recreate different network conditions, iperf3 helps measure the impact of these conditions on network performance. First, ensure that iperf3 is installed on both the client and server machines. Once you’ve set up the desired network conditions using netem, you can use iperf3 to measure the performance of your network, the basic commands are iperf3 -s for the server and iperf3 -c for the client for more information go to the iPerf3 man page.)

On the server machine, start iperf3 in server mode

iperf3 -s

On the client machine, initiate the test by connecting to the server:

iperf3 -c <server_ip>

More examples

You can use iperf3 to test UDP traffic use the -u flag

Server Side

iperf3 -s -u

Client Side

iperf3 -c <server_ip> -u

You also can specify a different port using the -p flag and set the test duration with the -t flag (in seconds)

Server Side

iperf3 -s -p <port_number>

Client Side

iperf3 -c <server_ip> -p <port_number> -t <duration>

You can test the impact of multiple parallel connections on network performance. Use the -P flag to specify the number of parallel client threads

Client Side

iperf3 -c <server_ip> -P <num_threads>

If you want to test the upload speed the -R flag to indicate reverse mode

Client Side

iperf3 -c <server_ip> -R


Testing applications in real-world network conditions is a crucial step in ensuring their reliability and performance. netem and iperf3 provide a powerful duo for emulating and evaluating different network scenarios. By harnessing the capabilities of these tools, developers can enhance their applications ability to handle adverse network conditions, ultimately delivering a better user experience.