Disclaimer #1

I am not an iptables expert. This tip will work best on your local linux development box where you probably have no iptables rules setup. Do not play around with this shit on production machines, unless you know what you are doing. Speak with your friendly sysadmins before doing this on any machine for which they feel responsible.

Disclaimer #2

According to this tip, do not drop more than 14% of the packets otherwise you will cause all tcp sockets to stall.

Introduction

Why would you want to do this? sometimes people (aka customers) might complain that your super-duper application that they use via the Internets (aka a series of tubes) is slow. One reason could be a dodgy internet connection and/or packet loss. See this great article about how packet-loss affects web applications and how to drop packets with a microwave oven.

And now finally…

To simulate a dropped packets with iptables, you can use the following commands (as root):

# for randomly dropping 10% of incoming packets:
iptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP

# and for dropping 10% of outgoing packets:
iptables -A OUTPUT -m statistic --mode random --probability 0.1 -j DROP

Once done, you can use the following for removing these packet-drops:

# for the incoming packets:
iptables -D INPUT -m statistic --mode random --probability 0.1 -j DROP

# and for the outgoing packets
iptables -D OUTPUT -m statistic --mode random --probability 0.1 -j DROP