Need some help with iptables. I always use to have vps with public ipv4 ip and used these rules in iptables to block ssh connections that tried to connect too many times.
-A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 180 --hitcount 3 --name DEFAULT --mask 255.255.255.255 --rsource -j DROP
-A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name DEFAULT --mask 255.255.255.255 --rsource
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
Input by default use to be set to BLOCK.
Before anyone says i should not use the default port 22 for ssh i dont... this is only for demonstration purposes. And yes i dont use root login and i use ssh keys.
Now i have nat vps that has limited amount of open ports that you can use and if i try to use these rules i can no longer ssh to the vps. All the other rules work fine except for these.
I tried to save the default iptable rules maybe someone can tell me why using above rules on this vps instantly blocks connection to ssh.
# Generated by iptables-save v1.4.21 on Fri Nov 5 22:58:56 2021
*raw
:PREROUTING ACCEPT [284:27162]
:OUTPUT ACCEPT [235:31044]
COMMIT
# Completed on Fri Nov 5 22:58:56 2021
# Generated by iptables-save v1.4.21 on Fri Nov 5 22:58:56 2021
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
# Completed on Fri Nov 5 22:58:56 2021
# Generated by iptables-save v1.4.21 on Fri Nov 5 22:58:56 2021
*security
:INPUT ACCEPT [284:27162]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [235:31044]
COMMIT
# Completed on Fri Nov 5 22:58:56 2021
# Generated by iptables-save v1.4.21 on Fri Nov 5 22:58:56 2021
*mangle
:PREROUTING ACCEPT [284:27162]
:INPUT ACCEPT [284:27162]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [235:31044]
:POSTROUTING ACCEPT [235:31044]
COMMIT
# Completed on Fri Nov 5 22:58:56 2021
# Generated by iptables-save v1.4.21 on Fri Nov 5 22:58:56 2021
*filter
:INPUT ACCEPT [284:27162]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [235:31044]
COMMIT
# Completed on Fri Nov 5 22:58:56 2021