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.
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 100msThis 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 10msExample 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 normalSimulating 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 100msEvery third packet is delayed by 100 ms, causing out‑of‑order delivery.
tc qdisc change dev eth0 root netem reorder 50% 15% delay 300msThis 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 eth0The 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
