Infrastructure Notes

How to Handle a SYN Attack on a Hosting Server Without Taking Down the Customer Website

By Nikhil Bhangale··7 min read

When a SYN flood hits one customer IP, null routing stops the attack but also takes the site offline. Here's a practical hosting workflow: confirm the attack, protect first, migrate when needed, and only blackhole as a last resort.

How to Handle a SYN Attack on a Hosting Server Without Taking Down the Customer Website

At 2:15 PM on a Tuesday, a multi-IP hosting node carrying sixty customer websites started timing out on TLS handshakes even though upstream bandwidth barely crossed 85 Mbps. In hosting operations, the reflex reaction is almost always asking the data center to null-route the targeted IP address so the server recovers. That blackhole stops the flood in seconds, and it also knocks a paying customer's website completely offline right when they need traffic flowing.

Most small and mid-sized TCP SYN floods do not saturate physical NIC capacity; they exhaust kernel socket state tables on a single IP and port. By confirming the backlog first, hardening the Linux TCP stack, placing a reverse-proxy edge in front of a rotated origin IP, and isolating tenants cleanly, you can stop the outage without taking down the customer site.

Confirm Server Load vs. Socket Backlog Exhaustion

Before editing firewall rules or routing tables, confirm whether the host faces a network state flood rather than an application bottleneck. A maxed-out PHP worker pool or locked database table can make HTTPS checks time out identically on external monitors.

Checking server load and network activity during a suspected SYN flood

Check load averages, memory pressure, and CPU time split between user processes (us) and kernel interrupt handling (sy):

bash · terminal
uptime
# 14:17:09 up 94 days, 6:12, 1 user, load average: 6.42, 4.11, 2.08

vmstat 1 3
# procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
#  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
#  7  0      0 4821900 312400 3910420  0    0     4    28 18420 9130 49 29 22  0  0

When CPU climbs near 78% with heavy interrupt rates (in above 18,000 per second) while memory stays flat around 52% and disk wait (wa) sits at zero, the kernel networking stack is absorbing packet pressure. If you instead see pure user-space CPU or storage wait, switch to diagnosing high CPU usage on Linux servers before touching packet filters.

Pinpoint Half-Open SYN-RECV Connections and the Targeted IP

In a normal TCP handshake, a client sends SYN, the kernel replies with SYN-ACK while holding a slot in SYN-RECV, and the client answers with ACK to reach ESTAB. During a SYN flood, spoofed sources or botnets send thousands of SYN packets per second without completing the final ACK, starving the listen queue.

Inspecting half-open SYN-RECV connections targeting a single hosting IP

Use ss (or netstat -ant on older nodes) to count half-open sockets and rank which local IP on your hosting server is targeted:

bash · terminal
ss -ant state syn-recv | tail -n +2 | wc -l
# 1842

ss -ant state syn-recv | awk 'NR>1 {print $4}' | sort | uniq -c | sort -rn | head -n 5
#    1819 203.0.113.45:443
#      18 203.0.113.10:443
#       5 203.0.113.45:80

nstat -az | grep -E 'TcpExtListenDrops|TcpExtTCPReqQFullDoCookies'
# TcpExtListenDrops               49210              0.0
# TcpExtTCPReqQFullDoCookies      128440             0.0

On legacy systems, netstat -ant | awk '$6 == "SYN_RECV" {print $4}' | sort | uniq -c | sort -rn gives the same ranking. Here, dedicated customer IP 203.0.113.45:443 holds 1,819 half-open sockets while shared IP 203.0.113.10 holds 18, identifying the exact virtual host under fire.

Harden the Linux TCP Stack and Avoid the Conntrack Trap

Your first local mitigation makes half-open handshakes cheap to track and fast to expire. Create /etc/sysctl.d/90-syn-mitigation.conf:

config / ini
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 8192
net.core.somaxconn = 8192
net.ipv4.tcp_synack_retries = 2

Apply with sysctl --system and reload Nginx or Apache so listen sockets adopt the raised somaxconn limit. Dropping tcp_synack_retries from 5 (~63 seconds) to 2 (~7 seconds) clears dead SYN-RECV slots nearly nine times faster while giving mobile users on lossy networks two retries.

Avoid a classic firewall mistake: placing stateful iptables or nftables rate limits on spoofed SYN floods without bypassing conntrack. Random spoofed source IPs allocate a fresh table entry per packet until nf_conntrack_count reaches nf_conntrack_max, printing nf_conntrack: table full, dropping packet in dmesg and dropping legitimate SSH and database traffic. Check sysctl net.netfilter.nf_conntrack_count net.netfilter.nf_conntrack_max first, and meter raw SYN bursts inside the raw hook (notrack):

bash · terminal
nft add table inet syn_guard
nft 'add chain inet syn_guard raw_pre { type filter hook prerouting priority raw; policy accept; }'
nft 'add rule inet syn_guard raw_pre ip daddr 203.0.113.45 tcp flags syn / syn,ack,fin,rst meter syn_src { ip saddr limit rate over 15/second burst 30 packets } notrack drop'

Scrub Traffic With a Reverse Proxy CDN and Rotate the Origin IP

Kernel tuning absorbs moderate floods, whereas sustained attacks belong at an Anycast CDN and WAF edge like Cloudflare or Fastly. Because the proxy completes the TCP handshake at the edge before forwarding valid HTTP/TLS requests, raw SYN floods never touch your origin daemon.

Filtering SYN flood traffic through a reverse proxy CDN and WAF

Flipping DNS to a proxy is only half the job because bots hammering 203.0.113.45 ignore DNS updates and scrape historical origin IPs from Passive DNS archives. To shed the attack cleanly:

  1. Enable CDN reverse-proxy mode with Full (Strict) TLS verification.
  2. Reassign the customer's virtual host in Nginx, Apache, or cPanel onto a clean secondary IP on the box (such as 203.0.113.88).
  3. Point the CDN's origin A record to 203.0.113.88 and lock ports 80 and 443 on that IP in nftables so only published CDN CIDRs can connect.
  4. Audit MX and mail. records so mail headers or DNS zones do not expose 203.0.113.88.

Decide Whether to Mitigate in Place or Migrate Clean Sites

Multi-tenant servers require clear trade-offs depending on whether the flood targets a dedicated IP or a shared IP hosting dozens of accounts.

Decision workflow between migrating clean sites vs mitigating in place

ScenarioRecommended ActionCustomer DowntimePrimary Operational Risk
Moderate flood on dedicated IPTune sysctl, proxy domain via CDN, rotate vhost to clean IPZero downtimeLeaving mail. subdomain pointing to the new origin IP
Flood on shared IP with 40+ sitesSpot targeted Host or TLS SNI in recent logs, move target to isolated IP + CDNUnder 2 minutesPure SYN packets carry no SNI until handshakes complete
Volumetric flood saturating 1 Gbps NICMigrate clean sites or target to scrubbed VPS, then blackhole old IP5-minute DNS TTL windowStale resolver caches if TTL was left at 3600s
Repeat target refusing proxy setupMove tenant onto isolated DDoS-filtered VLANScheduled windowNeighboring customers seeing recurring latency spikes

When handshakes fail before Nginx logs HTTP requests on a shared IP, check access log spikes from the minute right before TcpExtListenDrops rose, or sample companion PSH-ACK packets via tcpdump. Like the safeguards we added after our late-night 502 incident response, keeping zone DNS TTLs at 300 seconds turns emergency migrations into five-minute cutovers.

Reserve Null Routing Strictly for the Final Resort

Null routing locally (ip route add blackhole 203.0.113.45/32) or upstream via BGP Remote Triggered Black Hole (RTBH) drops every packet for that IP before it hits your server.

Why null routing drops both attack traffic and legitimate visitors

Upstream RTBH makes sense in only two cases: after live DNS traffic has cut over to a protected IP, or when multi-gigabit volumetric traffic saturates physical rack uplinks (rx_dropped climbing on ip -s link show eth0) and threatens neighboring machines. Otherwise, blackholing finishes the attacker's job. Confirm SYN-RECV sockets first, tune kernel queues, shield and rotate the origin IP behind an edge proxy, and save null routes for retired addresses.

#syn-flood#ddos#linux#nginx#cloudflare#incident-response#hosting
← Back to all posts

Related Articles

Browse all articles →
Infrastructure Notes12 min read

Moving to a CDN Without Overwhelming Your Origin (or Blocking Googlebot)

Learn how to migrate to a CDN like Cloudflare without triggering cache-miss storms on your Linux origin, breaking real visitor IPs, or accidentally blocking Googlebot.

Read article →
Infrastructure Notes11 min read

Microsoft Outlook Outage November 2026: What Broke, Who Was Hit, and How to Respond

How the November 2026 Exchange Online cascading server failure appeared on downstream Linux mail relays, with hands-on Postfix transport throttling, cPanel Exim triage, swaks diagnostics, and DKIM queue safety.

Read article →
Infrastructure Notes7 min read

The Risks of High Availability Automation During Network Instability

When network connectivity degrades, HA clusters cannot distinguish between a dead server and a flapping switch port. Learn how split-brain happens in Corosync, Pacemaker, and Proxmox HA, why missing hardware fencing corrupts shared storage, and how to build safer failover architectures.

Read article →
Chat on WhatsApp