CSchantz Wiki

Syn Flood Mitigation

Analyze

Check Syn Queue

netstat -tan | grep SYN_RECV | wc -l

(512 queue size is full)

Check Dropped Connections

netstat -s | grep -i "SYNs to LISTEN"

(users dropping)

Check for Origin Ips

netstat -an | grep SYN_RECV | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head -n 20

1st step mitigation

Test with CSF Mitigation first

nano /etc/csf/csf.conf

Conservative

SYNFLOOD = “1”
SYNFLOOD_RATE = "100/s
SYNFLOOD_BURST = "150"

More indepth

SYNFLOOD = “1”
SYNFLOOD_RATE = "100/s
SYNFLOOD_BURST = "150"

Nuclear option

Increase size of half open connections

sysctl -w net.ipv4.tcp_max_syn_backlog=8192
sysctl -w net.core.somaxconn=8192
sysctl -w net.core.netdev_max_backlog=8192

Enable SYN Cookies

sysctl -w net.ipv4.tcp_syncookies=1

Reduce timeout/retries for fake handshakes

sysctl -w net.ipv4.tcp_synack_retries=1
sysctl -w net.ipv4.tcp_fin_timeout=10

Immediately reset connections

sysctl -w net.ipv4.tcp_abort_on_overflow=1

Blackhole IPs if needed

ip route add blackhole 121.37.0.0/16   # Huawei
ip route add blackhole 113.44.0.0/16   # Tencent
ip route add blackhole 45.131.0.0/16   # High-risk VPS ranges
ip route add blackhole 92.118.0.0/16   # Global Botnet range