Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to forward TCP connections on a certain port of the machine A to another port on the machine B (which is actually the same that originated the connection to machine A) and simulate random or deterministic packet drops.

How can I do it with iptables?

share|improve this question
I think scapy and hping will be more appropiate for that – vnix27 Feb 28 '11 at 4:39

man what? right, man iptables:


This module matches packets based on some statistic condition. It supports two distinct modes settable with the --mode option.



This module randomly matches a certain percentage of all packets. --average percent Matches the given percentage. If omitted, a probability of 50% is set.

share|improve this answer

If using FreeBSD is an option ipfw in FreeBSD has got some excellent features to mimic various types of connections. It can add latency, packet loss etc. Very useful for testing WAN performance of an application.

There are commercial products to do this as well. I can recommend Linktropy, we use it extensively to test our in-house applications. The mini2 model only costs a few hundred USD and is enough for most usecases.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.