Added an iptables rule but getting “connection reset by peer” or you still cannot connect, then read on.

Run this command: sudo iptables -L –line-numbers

Always backup your existing rules first: sudo iptables-save > savedrules.txt

This is how you can restore your rules if you messed something up: sudo iptables-restore < savedrules.txt

Adding a new Rule

If you want to add a new rule, make sure to add it before the line marked in red. This is how you do it:

iptables list

sudo iptables -I INPUT 11-p tcp –dport 8001 -j ACCEPT

In my case I am adding my new rule onto line 11 which means it will be before the rule marked in red. Just change your port number.

Want to log rules, here is how:

sudo iptables -I INPUT -p tcp -m tcp –dport 8001 -m state –state NEW -j LOG –log-level 1 –log-prefix “New Connection “

Want to delete a rule on a specific line, here is how:

sudo iptables -D INPUT 1

The rule above says delete rule 1 in chain INPUT. Don’t just copy and paste this rule, first check with “sudo iptables -L –line-numbers” which rule you want to delete