📘 This content originated from JavaPipe’s website. JavaPipe has now merged with Mochahost, providing an improved range of hosting services with added benefits and dependable service quality. Check out the fastest hosting plans here: DDoS Protected Windows VPSThere are different ways of building your own anti-DDoS rules for iptables. We will be discussing the most effective iptables DDoS protection methods in this comprehensive tutorial. This guide will teach you how to: Select the best iptables table and chain to stop DDoS attacks
Tweak your kernel settings to mitigate the effects of DDoS attacks
Use iptables to block most TCP-based DDoS attacks
Use iptables SYNPROXY to block SYN floods
Please note that this article is written for professionals who deal with Linux servers on a daily basis. Table of Contents
- What Is IPtables?
- Why Your IPtables Anti-DDoS Rules Suck
- IPtables Tables
- IPtables Chains
- The Best Linux Kernel Settings to Mitigate DDoS
- Anti-DDoS Kernel Settings (sysctl.conf)
- The Actual IPtables Anti-DDoS Rules
- Block Invalid Packets
- Block New Packets That Are Not SYN
- Block Uncommon MSS Values
- Block Packets With Bogus TCP Flags
- Block Packets From Private Subnets (Spoofing)
- Additional Rules
- Mitigating SYN Floods With SYNPROXY
- The Complete IPtables Anti-DDoS Rules
- Bonus Rules
- Conclusion
Did you know we now offer [1Gbps unmetered VPS](https://javapipe.com/unmetered-vps/) plans with DDoS protection in Chicago, Illinois and Bucharest, Romania?
If they are able to reach your server, there isn’t much you can do against those multi-Gbit/s attacks except to move to a DDoS protected network.
What Is IPtables?
netfilter iptables (soon to be replaced by nftables) is a user-space command line utility to configure kernel packet filtering rules developed by netfilter. It’s the default firewall management utility on Linux systems – everyone working with Linux systems should be familiar with it or have at least heard of it. iptables can be used to filter certain packets, block source or destination ports and IP addresses, forward packets via NAT and a lot of other things. Most commonly it’s used to block destination ports and source IP addresses.Why Your IPtables Anti-DDoS Rules Suck
To understand why your current iptables rules to prevent DDoS attacks suck, we first have to dig into how iptables works. iptables is a command line tool used to set up and control the tables of IP packet filter rules. There are different tables for different purposes.IPtables Tables
Filter: The filter table is the default and most commonly used table that rules go to if you don’t use the -t (–table) option. NAT: This table is used for Network Address Translation (NAT). If a packet creates a new connection, the nat table gets checked for rules. Mangle: The mangle table is used to modify or mark packets and their header information. Raw: This table’s purpose is mainly to exclude certain packets from connection tracking using the NOTRACK target. As you can see there are four different tables on an average Linux system that doesn’t have non-standard kernel modules loaded. Each of these tables supports a different set of iptables chains.IPtables Chains
PREROUTING: raw, nat, mangle- Applies to packets that enter the network interface card (NIC)
- Applies to packets destined to a local socket
- Applies to packets that are being routed through the server
- Applies to packets that the server sends (locally generated)
- Applies to packets that leave the server
filter table doesn’t support the PREROUTING chain. To get around this problem, we can simply use the mangle table instead of the filter table for our anti-DDoS iptables rules.
It supports most if not all rules that the filter table supports while also supporting all iptables chains.
So you want to know why your iptables DDoS protection rules suck? It’s because you use the filter table and the INPUT chain to block the bad packets!
The best solution to dramatically increase the performance of your iptables rules and therefore the amount of (TCP) DDoS attack traffic they can filter is to use the mangle table and the PREROUTING chain!

