How to Use nftables SYN Proxy
SYN proxy in nftables protects servers from SYN flood attacks by completing TCP handshakes before forwarding connections to the real server. This guide walks through the specific troubleshooting steps to diagnose and resolve SYN proxy issues.
Before You Begin
Before you begin, be sure to have the following in place:
- A Linux server with the relevant software installed
- Access to the command line interface
- Appropriate permissions (root or sudo)
Quick Fix
Wrong
No SYN flood protection (server vulnerable to SYN floods)
Wrong: No SYN flood protection
Right
nft add chain ip raw prerouting { type filter hook prerouting priority -300; }\nnft add rule ip raw prerouting tcp dport 80 tcp flags & (syn|rst|ack) == syn notrack\nnft add rule ip filter input tcp dport 80 ct state invalid,untracked synproxy mss 1460 wscale 7 timestamp
Right: SYN proxy to mitigate SYN floods
Output
SYN proxy configured on port 80\n Notrack: SYN packets bypass connection tracking\n MSS: 1460, WScale: 7\n Client must complete TCP handshake with proxy before reaching backend
Prevention
To avoid future issues, follow these best practices:
- Use synproxy in the filter input chain for protected services
- The synproxy statement requires notrack in the raw table for initial SYN packets
- SYN proxy completes the TCP handshake before forwarding to the real server
- Configure MSS, wscale, and timestamp options to match backend
- SYN proxy is transparent to legitimate clients
DodaTech Tools
For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.
Common Mistakes with synproxy
- Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
These mistakes appear frequently in real-world NFTABLES code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro