drop fin packet with iptables rule

Os is linux mint 19, i want to setup a rule in iptables to drop the incomming FIN packet as a response of the FIN_WAIT_2 state. This for a given port. I want to test an application and need some connections staying in the FIN_WAIT_2 tcp state. Firewall is ufw


If you just want to drop the incoming FIN packet when you always initiate the shutdown of the connection, then a rule such as the following should suffice:

iptables -I INPUT --protocol tcp --destination-port 1337 --tcp-flags FIN FIN -j DROP

However this will mess up closing of connections by the other end of the connection. I don't think that it's possible to only drop the FIN if preceded by an ACK.