$ sudo tc qdisc del dev eth0 root netem loss 3% To delete the above queue discipline use the del command instead of add: Of course tc selects packets to drop randomly, and so we do not always get exactly 3% drops over 60 seconds. Out of the 5351 packets sent by A, 170 were dropped (not received by by). On computer B (the computer where tc is NOT used) run:Īnd now on computer A run a UDP test, sending at 1Mb/s for 60 seconds:Ĭlient connecting to 192.168.1.5, UDP port 5001
To show that it works, lets run an iperf UDP test. Qdisc netem 8001: root refcnt 2 limit 1000 loss 3% When using tc you can show the current queue disciplines using: You can use different values of loss (e.g. The above command tells the Linux kernel to drop on average 3% of the packets in the transmit queue. Netem is a special type of queuing discipline used for emulating networks. $ sudo tc qdisc add dev eth0 root netem loss 3% To randomly drop packets sent by computer A, on computer A run the command: Computer A transmits on interface eth0 (and in the output below, has IP address 192.168.1.116 B is 192.168.1.5). Because tc controls the transmit queues, we use it on a source computer (normally tc doesn't impact on what is received by your computer, but there are exceptions).Īssume we want to transfer data from A to B. giving priority to specific type of packets), as well as emulate links by delaying and dropping packets. tc allows you to change the queuing mechanisms (e.g. The packets are transmitted in a first-in-first-out (FIFO) order. Normally when applications on your computer generate data to send, the data is passed to your kernel (via TCP and IP) for transmission on the network interface. tc controls the transmit queues of your kernel. Here I will explain the use of both.įirst, lets use tc.
There is a online manual for iptables the man pages also describe the statistic module. A good description of using tc to drop packets (as well as other features) is available via the Linux Foundation site. There are two simple ways to randomly drop packets on a Linux computer: using tc, the program dedicated for controlling traffic and using iptables, the built-in firewall. Dropping Packets in Ubuntu Linux using tc and iptables