How to simulate delayed and dropped packets on Linux?

LinuxOperating SystemOpen Source

In order to simulate the packages that got delayed or dropped we can make use of the netem which provides us with a network emulation functionality that is helpful in testing protocols.

The way netem works is that it tests the protocols by emulating the properties of wide area networks.

There are different versions of netem and the current stable version allows us to emulate variable delay, loss, re-ordering and duplication of packets.

There are two ways in which we can use the network emulator, the first is the most basic one where we can enable the netem kernel component by following the simple steps mentioned below

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

Or we can make use of the command line, as the command line tool ‘tc’ is used for the netem kernel.

Let’s explore a few different examples of the command line tool tc, where we will first emulate a wide area of network delays then we will talk about the packet loss.

Emulating wide network delays


# tc qdisc add dev eth0 root netem delay 100ms

Now, if we do a simple ping test to our host on the local network. then we will see an increase of 100 milliseconds. The delay is normally limited by the clock resolution of the kernel (HZ).

We can also cause a delay without changing the qdisc, for that please consider the command shown below −

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

The above command will cause the added delay to be 100ms ± 10ms.

Packet Loss

We can specify the packet loss in the ‘tc’ command with the help of the percentages.

Consider the command shown below that simulates the same.


# tc qdisc change dev eth0 root netem loss 0.1%

The above command will cause 1/10th of a percent (i.e., 1 out of 1000) packets to be randomly dropped.

Updated on 31-Jul-2021 11:56:01