Back to articles
Technology Insight

Hardening the Linux Kernel: Optimizing Netfilter to Mitigate Low-to-Mid Scale SYN Flood DDoS Attacks

June 1, 2026

Introduction to the SYN Flood Threat

In the landscape of cybersecurity, the SYN Flood attack remains one of the most persistent and effective methods used by adversaries to disrupt service availability. Despite being a classic exhaustion attack, it continues to evolve. While massive, multi-terabit attacks require hardware-level scrubbing or cloud-based mitigation services, small to medium-scale attacks can often be mitigated directly at the server level through surgical precision in Linux Kernel Netfilter optimization.

This blog post explores the technical mechanics of the TCP three-way handshake and provides a comprehensive roadmap for system administrators and DevOps engineers to harden their Linux infrastructure against SYN-based resource exhaustion.

The Anatomy of a SYN Flood

To understand the defense, one must understand the offense. The TCP protocol establishes connections via a three-way handshake:

  1. SYN: The client sends a Synchronize packet.
  2. SYN-ACK: The server responds with a Synchronize-Acknowledgment and allocates memory in the 'backlog' queue for the half-open connection.
  3. ACK: The client completes the handshake with an Acknowledgment.

In a SYN Flood, the attacker sends a barrage of SYN packets from spoofed IP addresses and never sends the final ACK. The server's connection backlog fills up with 'half-open' states, eventually leading to a denial of service for legitimate users because the system can no longer accept new connections.

Phase 1: Kernel Parameter Optimization (sysctl)

The first line of defense is tuning the Linux kernel's networking stack via sysctl. These parameters determine how the system handles connection queues and timeouts.

1. Enabling TCP SYN Cookies

This is arguably the most critical setting. When net.ipv4.tcp_syncookies is enabled, the kernel stops allocating entries in the backlog queue when it becomes full. Instead, it sends a SYN-ACK with a cryptographically generated sequence number. Only if a valid ACK is returned will the server allocate memory for the connection.

Configuration: net.ipv4.tcp_syncookies = 1

2. Expanding the Backlog Queues

Standard Linux defaults are often too conservative for high-traffic environments. Increasing the size of the tcp_max_syn_backlog allows the server to hold more half-open connections before dropping them.

  • net.ipv4.tcp_max_syn_backlog = 4096: Increases the capacity for SYN requests.
  • net.core.somaxconn = 4096: Increases the maximum number of established connections waiting to be accepted by the application.

3. Reducing SYN-ACK Retries

By default, the kernel retries sending SYN-ACKs several times. During an attack, this consumes unnecessary bandwidth and CPU. Reducing the retry count allows the kernel to give up on dead connections faster.

net.ipv4.tcp_synack_retries = 2

Phase 2: Leveraging Netfilter and Nftables

While kernel tuning helps the system survive, Netfilter (the framework behind iptables and nftables) allows us to actively drop malicious traffic before it puts a heavy load on the TCP stack.

Implementing Rate Limiting

We can use the hashlimit module to ensure that no single IP address can flood the server with SYN packets while allowing legitimate traffic to pass through. Here is a conceptual example using iptables:

iptables -A INPUT -p tcp --syn -m hashlimit --hashlimit-name synflood --hashlimit-upto 20/second --hashlimit-burst 50 --hashlimit-mode srcip -j ACCEPT
iptables -A INPUT -p tcp --syn -j DROP

In this configuration, we allow up to 20 SYN packets per second from a specific source IP, with a burst of 50. Anything exceeding this threshold is dropped, effectively neutralizing high-frequency single-source floods.

The Power of the 'Raw' Table

To achieve maximum performance, we should drop packets as early as possible. The PREROUTING chain in the raw table allows us to drop packets before the kernel performs connection tracking (conntrack). Since conntrack is CPU-intensive, dropping packets here significantly reduces the performance impact of an attack.

Phase 3: Connection Tracking (Conntrack) Tuning

If your firewall uses connection tracking, the conntrack table can become a bottleneck. If the table fills up, the server will drop all incoming packets, including legitimate ones.

Increasing Table Size

Monitor your conntrack usage and increase the limits if necessary:

  • net.netfilter.nf_conntrack_max = 262144
  • net.netfilter.nf_conntrack_tcp_timeout_syn_recv = 30 (Reducing the timeout for SYN_RECV state)

Advanced Mitigation: Nftables Synproxy

For high-performance environments, the SYNPROXY target in nftables is a game-changer. It acts as a proxy between the client and the server's TCP stack, performing the SYN cookie handshake within Netfilter itself. The real backend server only sees a connection after the three-way handshake is fully completed.

Benefits of Synproxy:

  • The backend application never sees the SYN flood.
  • Protects against attacks that use large window sizes or specific TCP options.
  • Highly scalable on multi-core systems.

Monitoring and Validation

Optimization is not a "set and forget" task. Use tools like netstat -n -p TCP | grep SYN_RECV | wc -l to monitor the number of half-open connections. Furthermore, utilize nstat to track SNMP counters like TcpExtTCPBacklogDrop or TcpExtSyncookiesSent to verify if your optimizations are being triggered during traffic spikes.

Conclusion

Mitigating SYN Flood attacks is a multi-layered process. By combining kernel sysctl tuning to handle resource allocation, Netfilter rate-limiting to block aggressive sources, and Synproxy for advanced protection, you can transform a vulnerable Linux server into a hardened bastion. While these techniques are highly effective for small to medium attacks, always remember that defense-in-depth is key; for large-scale volumetric attacks, these local optimizations should be paired with edge-based scrubbing solutions.

By proactively configuring your Netfilter stack today, you ensure that your services remain resilient and available even when under pressure.

Hardening the Linux Kernel: Optimizing Netfilter to Mitigate Low-to-Mid Scale SYN Flood DDoS Attacks | DPTCloud