title: Using iptables to emulate broken connection
body: <p>I have some bug in tcp communication betweeen my soft and server. On timeout router <strong>silently</strong> closes connection without informing client about it ( normally it is made with FIN packet ).</p>
  
  <p>My tcpdump log in this situation:</p>
  
  <p>Soft tries to push message in opened connection.</p>
  
  <p><code>09:29:41.438050 IP CLIENTIP.33668 &gt; SERVERIP.8101: Flags [P.], seq 163:228, ack 144, win 229, options [nop,nop,TS val 96713087 ecr 4169733508], length 65</code></p>
  
  <p>On the server (actually middle ) side this connection was already broken and server answeres with Reset package.</p>
  
  <p><code>09:29:41.447415 IP SERVERIP.8101 &gt; CLIENTIP.33668: Flags [R], seq 3072817047, win 0, length 0</code></p>
  
  <p>I am trying to debug this case but this situtation happenes only after pretty long timeouts. </p>
  
  <p>My Idea was to emulate this situation using iptables. For example change destination port for my client:</p>
  
  <p><code>sudo iptables -t nat -D OUTPUT -p tcp --destination-port 8101 -j DNAT --to-destination SERVERIP:8102</code></p>
  
  <p>But this rule works only for new tcp connection, but i need to change packet content on already established connection. Does somebody know how can i write tcpdump rule to destination port on all packages ?</p>