Protection

8 min readUpdated

Can a firewall stop a DDoS attack?

Quick answer

A host or on-premises firewall cannot stop a DDoS attack that saturates your uplink, because the packets have used the bandwidth before the firewall sees them. What it can do is real but local: drop malformed packets, rate-limit new connections per source and rely on SYN cookies so a SYN flood cannot exhaust the backlog. A stateful firewall also has its own connection table, which a flood can fill until it drops legitimate traffic, making the firewall itself the target.

01Can a firewall stop a DDoS attack?

Not the kind that matters most. A firewall running on your server or at the edge of your own network cannot stop a volumetric flood that fills your internet link, because by the time a packet arrives at the firewall it has already travelled down the link and used its capacity. Dropping it locally frees nothing upstream. For that class of attack the traffic must be absorbed on a network with far more capacity than the attack, before it ever reaches you.

That does not make a firewall useless. It is essential for reducing attack surface and it does real work against smaller and non-volumetric attacks: it can drop packets that are obviously junk, limit how many connections one address may open, rate-limit new connections, and work with the kernel's SYN-cookie defence against SYN floods. The honest position is that a firewall is a necessary layer, not a DDoS solution on its own.

The confusion usually comes from mixing up the layers. A packet filter decides whether to accept a packet; it does not add bandwidth and it does not understand application requests. The sections below show precisely what it can do, where its own state table becomes the weak point, and the maths that decides when it stops helping. For the fuller defensive picture, see what DDoS mitigation is and remote DDoS protection.

02What can a firewall actually do against DDoS?

Plenty, as long as the attack does not exceed your link or the firewall's own capacity. The useful measures are all about dropping clearly bad traffic cheaply and limiting how much any one source can demand. These are worth configuring on every internet-facing host regardless of whether you also buy upstream protection.

The most important single defence against a SYN flood is not a firewall rule at all but a kernel feature, SYN cookies, which let the host answer a SYN without allocating connection state until the handshake completes. The firewall's job is to complement it: refuse packets that are not valid new-connection starts, cap new-connection rate per source, and drop traffic that conntrack marks invalid.

  • Drop packets that are not a valid new-connection start (for TCP, a bare SYN) and anything conntrack marks invalid
  • Rate-limit new connections per source address, so one host cannot open thousands per second
  • Drop protocols and ports you do not serve, reducing the surface an attacker can reach
  • Rely on SYN cookies for SYN floods rather than trying to track every half-open connection
  • Pair the host firewall with a default-deny baseline so only expected traffic is ever considered
SYN-flood defence lives in the kernel
# answer SYNs without allocating state when the backlog overflows
sysctl net.ipv4.tcp_syncookies      # default 1 (on)

# per-listener limit on half-open (SYN_RECV) connection requests
sysctl net.ipv4.tcp_max_syn_backlog
# cap on the listen() backlog of completed connections; default 4096
sysctl net.core.somaxconn

03What does a sensible per-source limit look like?

A practical ruleset accepts established traffic cheaply, drops invalid packets, keeps ICMP for path-MTU, error messages and IPv6 neighbour discovery but caps echo requests, and rate-limits new connections per source using dynamic sets for IPv4 and IPv6. The nftables ruleset below was checked and loaded in an isolated network namespace; it is illustrative, and real limits depend on your traffic. It allows SSH on port 22: change that to your real admin port before loading it, or you will lock yourself out.

nftables: per-source new-connection limit (passes nft -c, nftables 1.0.6)
table inet host {
    set new4 { type ipv4_addr; flags dynamic; timeout 1m; size 65536; }
    set new6 { type ipv6_addr; flags dynamic; timeout 1m; size 65536; }

    chain input {
        type filter hook input priority filter; policy drop;
        ct state established,related accept
        ct state invalid drop
        iif "lo" accept
        # keep ICMP for path-MTU, errors and IPv6 neighbour discovery; cap echo requests
        icmp type echo-request limit rate 10/second accept
        icmpv6 type echo-request limit rate 10/second accept
        icmp type echo-request drop
        icmpv6 type echo-request drop
        meta l4proto { icmp, ipv6-icmp } accept
        # a new TCP connection must start with a bare SYN
        tcp flags & (fin|syn|rst|ack) != syn ct state new drop
        # cap how fast one address may open new connections (22 = SSH, keep your admin port)
        tcp dport { 22, 80, 443 } ct state new update @new4 { ip saddr limit rate over 30/second burst 60 packets } drop
        tcp dport { 22, 80, 443 } ct state new update @new6 { ip6 saddr limit rate over 30/second burst 60 packets } drop
        tcp dport { 22, 80, 443 } ct state new accept
    }
}

04Where does the firewall itself become the target?

A stateful firewall remembers every connection in a connection-tracking (conntrack) table. That is what lets it accept established traffic cheaply, but it is also a finite resource an attacker can aim at. Every new connection, and on Linux every new UDP flow, creates an entry. Flood the host with enough distinct new flows and the table fills.

When it fills, the kernel logs "nf_conntrack: table full, dropping packet" and starts dropping new connections, including legitimate ones. The attacker has turned the very mechanism that was supposed to protect you into the thing that denies service. This is why a stateful firewall can make a large flood worse than a stateless filter would: it is doing bookkeeping that the attack is designed to overflow.

The maths is worth knowing. On Linux 6.1 nf_conntrack_max defaults to the hash-table size, which is total memory divided by 16,384 and capped at 262,144, so a host with roughly 4 GB of RAM or more gets 262,144 entries. A spoofed UDP flood that creates one new entry per packet, each held for the 30-second UDP timeout, fills an empty table in one second at 262,144 packets per second, which is small by flood standards. Raising the limit buys headroom at the cost of memory; it does not change the fact that the table is a target.

Watch the conntrack table under load (read-only)
# current limit and live count
sysctl net.netfilter.nf_conntrack_max      # e.g. 262144 on a 4GB+ host
cat /proc/sys/net/netfilter/nf_conntrack_count

# how long entries linger: one-way UDP flows, such as a spoofed flood, get 30 s
sysctl net.netfilter.nf_conntrack_udp_timeout          # default 30
sysctl net.netfilter.nf_conntrack_udp_timeout_stream   # default 120, two-way flows
sysctl net.netfilter.nf_conntrack_tcp_timeout_syn_recv # default 60

# the table-full drops and early evictions are counted here
cat /proc/net/stat/nf_conntrack

06Firewall vs DDoS protection: how they divide the work

They solve different problems and belong together. A firewall is an access-control and hygiene layer on the host: default-deny, least-privilege, drop the junk, limit per-source abuse. DDoS protection is upstream capacity and filtering that keeps a flood off your link entirely, plus, for websites and APIs, request-level inspection that a packet filter cannot do.

A sound setup uses both. Keep a tight host firewall for everything that does reach the box, and put dedicated protection in front for the attacks the firewall cannot stop alone: volumetric floods, packet-rate floods and application-layer floods. For websites that means a reverse-proxy web application firewall and rate limiting above the host; for raw network traffic it means upstream scrubbing on a remote network with capacity to spare.

  • Firewall: access control, dropping malformed packets, per-source connection limits, SYN cookies
  • Upstream protection: capacity to absorb volumetric and packet-rate floods before your link
  • WAF: request-level inspection for Layer 7 floods a packet filter cannot read
  • Together they cover surface, volume and application; none of the three replaces the others

Questions

Frequently asked questions

01Can a firewall stop a DDoS attack on its own?
No. A firewall on your server or network edge cannot stop a flood that saturates your uplink, because the traffic has already consumed the bandwidth before the firewall inspects it. It can block small single-source floods, drop malformed packets and rate-limit connections, but large volumetric, packet-rate and application-layer attacks have to be absorbed upstream on a network with spare capacity. Use a firewall as one layer, not the whole defence.
02Does a stateful firewall help or hurt during a flood?
Both. It helps by cheaply accepting established connections and dropping invalid packets, but it keeps a connection-tracking table that a flood of new or spoofed flows can fill. When the table is full the kernel drops new connections, including legitimate ones, so the firewall itself becomes the point of failure. Against a large flood a stateful firewall can fail before the bandwidth does.
03What is the difference between a firewall and DDoS protection?
A firewall decides which packets to accept on a host or network you own; it adds no bandwidth and cannot read application requests. DDoS protection is upstream capacity and filtering that keeps a flood off your link in the first place, plus request-level inspection for Layer 7 attacks. The firewall handles what reaches it; protection stops the flood from reaching it. They are complementary layers.
04Will SYN cookies stop a SYN flood?
They are the right tool for it. SYN cookies let the kernel answer a SYN without allocating connection state until the final handshake packet arrives, so a flood of half-open connections cannot exhaust the backlog. On Linux tcp_syncookies defaults to on. They do not help against a flood that saturates your uplink, which is a bandwidth problem, not a state problem, and must be handled upstream.
05Why does my firewall log say nf_conntrack table full?
Because the connection-tracking table has reached its limit and the kernel is dropping new connections. This happens under a flood of many new or spoofed flows, each creating an entry held for its timeout. On a host with roughly 4 GB of RAM or more the default is 262,144 entries, which a spoofed UDP flood of 262,144 new flows per second fills in one second. Raising the limit buys headroom but the table remains a deliberate target.

Sources

Sources and verification

Checked on 13 November 2026 on Debian 12: the nftables ruleset in “What does a sensible per-source limit look like?” passes nft -c (nftables 1.0.6). Other configuration, commands, log lines and output on this page are examples: adapt them to your system and check them before use.

  1. 01Linux kernel: nf_conntrack sysctl reference · kernel.org
  2. 02Linux kernel: IP sysctl (tcp_syncookies, tcp_max_syn_backlog) · kernel.org
  3. 03Why IPS and Firewalls Are Not Anti-DDoS Solutions · NSFOCUS
  4. 04Protecting Firewall Capacity from DDoS and Other Threats · NETSCOUT
  5. 05nftables wiki: rate limiting and dynamic sets · Netfilter

Last updated