· 8 min read

SYN Flood Protection: SYN Cookies, SYN Proxy, Asymmetry

SYN flood protection comes down to one idea: don't commit server memory to a TCP connection until the client proves it can receive packets at its claimed address. SYN cookies do this on the host, SYN proxy does it in front of the host, and both get harder when inbound and outbound traffic take different paths.

This guide covers how SYN and SYN-ACK floods work, how to spot them, how to configure Linux defenses, and what breaks in asymmetric networks.

How a SYN flood works

A normal TCP handshake has three steps: the client sends SYN, the server answers SYN-ACK, and the client completes with ACK. After the first SYN, the server allocates a request socket in the SYN_RECV state and retransmits the SYN-ACK if no ACK arrives.

In a SYN flood the attacker sends a large number of SYNs, usually with spoofed source addresses, and never completes the handshake. Two things get exhausted:

Because the sources are spoofed, the SYN-ACKs go to innocent third parties. Blocking by source IP is useless.

How a SYN-ACK flood works

"SYN-ACK flood" describes two different attacks, and the defenses differ.

1. Direct SYN-ACK flood. The attacker sends unsolicited SYN-ACK packets at your IP and ports. Your host has no matching connection, so it answers with RST. That costs CPU and bandwidth, and a stateful firewall or conntrack table still has to classify every packet.

2. Reflected SYN-ACK flood. The attacker sends SYNs to many public servers with your IP as the spoofed source. Those servers answer with SYN-ACKs, and retransmit them, toward you. The traffic comes from real servers, with source ports like 80 and 443, so it looks like legitimate replies.

Neither variant can be fixed by SYN cookies, because your host isn't the one answering a SYN. The fix is to drop SYN-ACKs that don't match anything you initiated, as early as possible, ideally upstream of your link.

Recognize the attack

Check kernel logs and counters first:

# Kernel message when cookies kick in
dmesg | grep -i "possible SYN flooding"

# Counters: cookies sent, queue overflows, drops
nstat -az TcpExtTCPReqQFullDoCookies TcpExtListenOverflows TcpExtListenDrops

# Half-open connections on 443
ss -H -tn state syn-recv '( sport = :443 )' | wc -l

Then capture a sample to see which variant you have:

# SYN only
tcpdump -nn -i eth0 'tcp[tcpflags] == tcp-syn' -c 50

# SYN-ACK only
tcpdump -nn -i eth0 'tcp[tcpflags] & (tcp-syn|tcp-ack) == (tcp-syn|tcp-ack)' -c 50

Many different source IPs with identical packet sizes and no follow-up ACKs point to a SYN flood. Lots of inbound SYN-ACKs with no outgoing SYNs from you point to a SYN-ACK flood.

Host-level defense: SYN cookies

With SYN cookies, the server doesn't store state after the SYN. It encodes a hash of the connection tuple, a coarse timestamp, and an MSS index into the initial sequence number of the SYN-ACK. If a valid ACK returns, the server rebuilds the state from the acknowledgment number. Spoofed sources never answer, so they cost no memory.

Linux settings:

# 1 = use cookies only when the SYN queue overflows
# 2 = always use cookies (useful for testing)
sysctl -w net.ipv4.tcp_syncookies=1

# Give legitimate clients more room before cookies kick in
sysctl -w net.ipv4.tcp_max_syn_backlog=8192
sysctl -w net.core.somaxconn=4096

# Fewer SYN-ACK retransmits means half-open entries expire sooner
sysctl -w net.ipv4.tcp_synack_retries=3

Persist them in /etc/sysctl.d/99-synflood.conf. Also raise the application backlog, for example listen 443 ssl backlog=4096; in nginx. The kernel caps it at somaxconn.

Limitations of SYN cookies:

SYN proxy: validate before the backend sees it

A SYN proxy sits in front of the protected server, typically on a firewall or filtering node. It answers the client's SYN with its own cookie-based SYN-ACK. Only when a valid ACK arrives does it open a real connection to the backend. It then translates sequence numbers between the two halves for the life of the flow.

The backend never sees spoofed SYNs, and no state is kept for unvalidated clients. It also protects hosts and applications that handle half-open connections poorly.

Linux has this built in as the SYNPROXY target. A working iptables example for a web server on port 443:

sysctl -w net.ipv4.tcp_syncookies=1
sysctl -w net.ipv4.tcp_timestamps=1
sysctl -w net.netfilter.nf_conntrack_tcp_loose=0

# Skip conntrack for incoming SYNs
iptables -t raw -I PREROUTING -i eth0 -p tcp -m tcp --syn --dport 443 -j CT --notrack

# Hand untracked and invalid packets to SYNPROXY
iptables -A INPUT -p tcp -m tcp --dport 443 \
  -m conntrack --ctstate INVALID,UNTRACKED \
  -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460

# Drop whatever is still invalid
iptables -A INPUT -m conntrack --ctstate INVALID -j DROP

Set --mss and --wscale to match your backend's real values. nftables has an equivalent synproxy statement.

Common mistakes:

Dealing with SYN-ACK floods

Since SYN cookies and SYN proxy are about incoming SYNs, use different tools for SYN-ACK floods:

The asymmetric traffic problem

Asymmetric routing means packets from a client reach you on one path, while your replies leave on another. It's common in multihomed networks with several transit providers, and in setups where DDoS-cleaned traffic arrives through a tunnel but replies go straight out the local uplink.

Stateful defenses assume they see both directions of a flow. When they don't:

Fixes

  1. Make the path symmetric. If traffic arrives through a GRE tunnel, send replies for the protected prefix back through it with policy routing:
ip rule add from 192.0.2.0/24 table 100
ip route add default dev gre1 table 100
  1. Keep stateful devices on the common path, or put the SYN proxy on the host itself, where it sees both directions by definition.
  2. Use stateless filters at asymmetric edges. Rate limits, bogon filters, and ACLs on source ports work without state.
  3. Detect with flow data. NetFlow, sFlow, or IPFIX records show SYN-only and SYN-ACK-heavy flows on every router, no matter where the return traffic goes. That makes flow-based detection a good fit for asymmetric networks.

Where host defenses stop

All of the above protects CPU, memory, and connection tables. If the attack saturates your uplink, the packets are already lost before your server can drop them. Volumetric SYN and SYN-ACK floods have to be stopped upstream, with filtering at the network edge or by routing clean traffic to you.

At Nixcon we run our own network (AS40368) with points of presence in Frankfurt and Fremont and a main data center in Izmir. Our DDoS protection and firewall service filters floods before they reach your server. If you have your own ASN and prefix, NixGuard Edge delivers clean traffic over a GRE tunnel with a BGP session. To see which flows are hitting you and when, NixMon provides flow-based monitoring and DDoS detection.

Quick checklist

Frequently asked questions

Are SYN cookies enough to stop a SYN flood?

They protect the host's connection memory, but not CPU cost or link saturation. A large flood can still fill your uplink or overload the network stack, so you also need rate limiting, SYN proxy, or upstream filtering.

What is the difference between a SYN flood and a SYN-ACK flood?

A SYN flood sends many SYN packets (usually spoofed) to your listening port to exhaust handshake state. A SYN-ACK flood sends SYN-ACK packets to your IP, either directly or by reflection off third-party servers that were tricked into replying to you. SYN cookies only help with the first.

Does SYN proxy work with asymmetric routing?

Not reliably. The proxy must see the backend's SYN-ACK to translate sequence numbers. If replies bypass it, connections fail. Fix the return path with policy routing, or run SYNPROXY on the host that terminates the traffic.

Should I set tcp_syncookies to 2?

Usually not in production. Value 1 uses cookies only when the queue overflows, which keeps full TCP option support for normal clients. Value 2 forces cookies always and is mainly for testing.

Need SYN flood filtering upstream? Talk to Nixcon about DDoS protection.Learn more