Operations 8 min read

How to Simulate Real-World Network Conditions with Linux Netem and tc

This guide explains how to use Linux's Netem module via the tc command to emulate network conditions such as delay, loss, duplication, corruption, and packet reordering, providing practical examples and command syntax for effective testing and troubleshooting of network performance issues.

Efficient Ops
Efficient Ops
Efficient Ops
How to Simulate Real-World Network Conditions with Linux Netem and tc

Simulating Network Conditions with Netem

In operations, the most complex problems are often network‑related, and the hardest part is reproducing them. Netem, available in Linux kernels 2.6 and later, is a powerful network emulation module that can simulate low bandwidth, latency, packet loss, and other common network faults.

Netem is controlled through the tc (traffic control) command, which is part of the iproute2 suite. tc manages traffic by queuing packets at the output interface, allowing you to limit or shape outgoing traffic.

The main tc actions for Netem are add (create a rule), change (modify an existing rule), replace (replace a rule), and del (delete a rule).

Simulating Delay

tc qdisc add dev eth0 root netem delay 100ms

This command adds a 100 ms delay to all packets sent on eth0. Netem also supports jitter, correlation, and distribution parameters:

JITTER : adds random variation (e.g., 10 ms) to the base delay.

CORRELATION : sets the percentage similarity between consecutive delay events.

distribution : chooses a delay distribution such as uniform, normal, pareto, or paretonormal.

Example with jitter:

tc qdisc add dev eth0 root netem delay 100ms jitter 10ms

Example with correlation:

tc qdisc add dev eth0 root netem delay 100ms 25%

Example with a specific distribution:

tc qdisc add dev eth0 root netem delay 100ms distribution normal

Simulating Packet Loss

tc qdisc add dev eth0 root netem loss 50%

This introduces a 50 % packet loss rate. Loss can also have a correlation factor: tc qdisc add dev eth0 root netem loss 50% 25% Here, 50 % of packets are dropped, and the loss of the current packet is 25 % correlated with the previous one.

Simulating Packet Duplication

tc qdisc add dev eth0 root netem duplicate 50%

This creates duplicate packets at a 50 % rate, with optional correlation similar to loss.

Simulating Packet Corruption

tc qdisc add dev eth0 root netem corrupt 30%

This corrupts 30 % of packets, which can be observed as increased loss in tools like ping.

Simulating Packet Reordering

Netem provides two methods to reorder packets.

tc qdisc add dev eth0 root netem reorder 50% gap 3 delay 100ms

Every third packet is delayed by 100 ms, causing out‑of‑order delivery.

tc qdisc change dev eth0 root netem reorder 50% 15% delay 300ms

This randomly reorders 50 % of packets with a 15 % correlation and adds a 300 ms delay to the reordered packets.

Viewing Current Netem Configuration

tc qdisc show dev eth0

The show command lists all active Netem rules, helping you verify and adjust the simulated network conditions.

Using Netem to emulate weak network environments is essential for testing and troubleshooting network‑related issues.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

network troubleshootingLinuxtraffic controlnetwork simulationnetemtc
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.