How to simulate delayed and dropped packets on Linux?

Network emulation (netem) is a Linux kernel component that provides network emulation functionality for testing protocols by simulating real-world network conditions like delays, packet loss, and reordering. It emulates the properties of wide area networks, making it invaluable for network testing and protocol development.

The current stable version of netem allows emulation of variable delay, packet loss, packet reordering, and packet duplication. This makes it possible to test how applications and protocols behave under various network conditions without requiring actual network infrastructure.

Enabling netem

There are two ways to use the network emulator. First, you can enable the netem kernel component through the kernel configuration −

Networking ->
    Networking Options ->
        QoS and/or fair queuing ->
            Network emulator

Alternatively, you can use the command line tool tc (traffic control), which provides an interface to the netem kernel functionality. The tc command is the primary method for configuring netem rules.

Emulating Network Delays

To simulate network delays, use the following command −

# tc qdisc add dev eth0 root netem delay 100ms

This command adds a 100ms delay to all packets leaving through the eth0 interface. When you perform a ping test to a host on the local network, you will observe an additional 100ms latency. The delay precision is limited by the kernel's clock resolution (HZ).

Variable Delay

You can introduce variable delay to make the simulation more realistic −

# tc qdisc change dev eth0 root netem delay 100ms 10ms

This command creates a delay of 100ms ± 10ms, meaning packets will be delayed by a random amount between 90ms and 110ms, simulating jitter in real networks.

Simulating Packet Loss

Packet loss can be simulated using percentages in the tc command −

# tc qdisc change dev eth0 root netem loss 0.1%

This command causes 0.1% packet loss, meaning 1 out of every 1000 packets will be randomly dropped. You can adjust the percentage to simulate different network conditions − higher percentages for poor network conditions, lower for stable connections.

Combined Effects

You can combine multiple network impairments in a single command −

# tc qdisc change dev eth0 root netem delay 200ms 50ms loss 1%

This creates both variable delay (200ms ± 50ms) and 1% packet loss simultaneously.

Removing netem Rules

To remove all netem rules and restore normal network behavior −

# tc qdisc del dev eth0 root

Conclusion

Network emulation using netem provides a powerful way to simulate various network conditions on Linux systems. By introducing controlled delays and packet loss, developers can test how their applications perform under different network scenarios without requiring complex network infrastructure setup.

Updated on: 2026-03-17T09:01:38+05:30

755 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements