Whilst setting up a VPS (specifically the firewall rules), I came across this article on using iptables to mitigate against DDOS attacks. I've seen this article referenced in a few places around the web so I tried implementing the rules as it advises.
Now, everything was fine until I added this rule from the 'Mitigating SYN Floods With Synproxy' section as shown below...
iptables -t raw -A PREROUTING -p tcp -m tcp --syn -j CT --notrack
When I added this rule, I immediately lost the ability to connect to/contact my server (port 80, SSH—although the currently open SSH session remained connected).
I tried to disabling UFW and it seemed to work OK, so I disabled UFW completely and just set up some basic iptables rules (I no longer use UFW).
I tried entering the rules as per the article again and the same thing happened.
If I just add the rule shown above (and no others from the article) then I don't lose my connection, so went through each of the original rules do determine which one was causing the issue and this is what I found...
The first rule in the article...
iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP
... is what seems to be causing the issue when used in conjunction with the rule referenced above (please note I've also added the Kernel rules into sysctl.conf as recommended).
Here are my iptables rules (for the sake of brevity, I have omitted most of the rules from the referenced article, and am just using the rules which seem to be causing the issue).
*raw
:PREROUTING ACCEPT [537:54944]
:OUTPUT ACCEPT [290:34648]
-A PREROUTING -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j CT --notrack
COMMIT
*mangle
:PREROUTING ACCEPT [580:65738]
:INPUT ACCEPT [580:65738]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [372:43208]
:POSTROUTING ACCEPT [372:43208]
-A PREROUTING -m conntrack --ctstate INVALID -j DROP
COMMIT
*filter
:INPUT DROP [15:5300]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [21:4232]
-A INPUT -s 127.0.0.0/8 ! -i lo -j REJECT --reject-with icmp-port-unreachable
-A INPUT -i lo -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp -m conntrack --ctstate INVALID,UNTRACKED -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460
-A INPUT -m conntrack --ctstate INVALID -j DROP
COMMIT
I've been searching for some clues as to why this is happening for about a week now but have so far had no joy, and would appreciate if someone more conversant than I with iptables could throw some light on this for me or point me in the right direction.
PS I'm using Ubuntu Server 20.04