Limit the number of incoming TCP connections.
iptables -N syn_flood
iptables -A INPUT -p tcp --syn -j syn_flood
iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
iptables -A syn_flood -j DROP
--limit 1/s: Maximum average matching rate in seconds
--limit-burst 3: Maximum initial number of packets to match
Limit incoming connection to HTTP server (port TCP 80) no more than 4 connections in a 10 seconds.
iptables -I INPUT 1 -p tcp --dport 80 -m state --state NEW -m recent --name http --update --seconds 10 --hitcount 5 -j REJECT --reject-with tcp-reset
iptables -I INPUT 2 -p tcp --dport 80 -m state --state NEW -m recent --name http --set
or
iptables -I INPUT 1 -p tcp --dport 80 -m state --state NEW -m recent --name http --update --seconds 10 --hitcount 5 -j DROP
iptables -I INPUT 2 -p tcp --dport 80 -m state --state NEW -m recent --name http --set
Make sure NEW incoming tcp connections are SYN packets; otherwise we need to drop them.
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
Packets with incoming fragments drop them. This attack result into Linux server panic such data loss.
iptables -A INPUT -f -j DROP
Incoming malformed XMAS packets drop them.
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
Incoming malformed NULL packets.
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP