Protection

6 min readUpdated

How to stop a DDoS attack

Quick answer

If an attack is happening right now, the fastest route back online is to get your traffic behind a network that can absorb it — for a website that means moving DNS to a reverse proxy, and for anything else it means routed transit. Before that helps you have to confirm it is actually an attack rather than a traffic spike or an outage, and you have to make sure your origin address cannot be reached directly, or the attacker will simply bypass whatever you put in front of it. Blocking individual addresses and rebooting the server are the two most common reactions and neither works against a distributed attack.

01First: confirm it is an attack

A genuine traffic spike, an application fault, an upstream network problem and an attack all present as "the site is down", and acting on the wrong one wastes the time that matters most. The read-only checks in signs of a DDoS attack separate them in a few minutes, from the link inwards to the application. If the site already sits behind a proxy, a 502 bad gateway or a 504 gateway timeout points at the origin rather than at the network in front of it.

02While it is happening

The order matters. Getting protection in place is useless if the attacker can still reach the address behind it.

  • Get behind a network with capacity — for HTTP, point DNS at a reverse proxy; for anything else, arrange routed or tunnelled transit
  • Check the TTL on the records you are about to change: resolvers keep the old answer for up to that long, and lowering it now only helps once the old value has expired
  • Firewall the origin to accept web traffic only from your provider's published ranges, or the attack simply continues around your new protection; hiding your origin IP covers the other leaks to close
  • Turn on the strictest protection mode you have while you stabilise, then relax it
  • Cache aggressively — anything served from cache never touches your origin
  • Tell your host: they see the traffic before you do and may already be null-routing you
Origin lockdown: only the provider may reach ports 80 and 443 (nft 1.0.6; example ranges from the documentation blocks)
#!/usr/sbin/nft -f
# Replace the example ranges with the list your provider publishes.
# Re-running the file replaces this table and leaves other rules alone.
table inet origin_lock
delete table inet origin_lock

table inet origin_lock {
    set proxy4 {
        type ipv4_addr
        flags interval
        elements = { 203.0.113.0/24, 198.51.100.0/24 }
    }
    set proxy6 {
        type ipv6_addr
        flags interval
        elements = { 2001:db8::/32 }
    }

    chain input {
        type filter hook input priority filter; policy accept;
        iif "lo" accept
        ct state established,related accept
        tcp dport { 80, 443 } ip saddr @proxy4 accept
        tcp dport { 80, 443 } ip6 saddr @proxy6 accept
        tcp dport { 80, 443 } counter drop
    }
}

03Pick the route back online by what is under attack

The fix depends less on the attack than on what it is aimed at. A website can be moved behind protection with a DNS change; most other services cannot, and knowing that before you start saves an hour of trying the wrong thing.

What is attackedFastest route backWhat to watch
Website or HTTP APIPoint DNS at a reverse proxy with DDoS capacityEvery hostname that still resolves to the origin
Game server or other UDP serviceRouted or tunnelled transit that filters UDP rather than dropping itThe real address published in server lists or launchers
Mail serverKeep MX on a separate host; a web proxy does not carry SMTPMX records that point at the same address as the website
DNS serverSecondary or hosted DNS on a network with capacityOpen recursion, which turns your server into a reflector
Your own address blockUpstream filtering announced over BGP, with clean traffic delivered back by tunnelWhether the provider can announce your prefix at all
Anything your host has null-routedMove the service behind protection first, then ask for the null route to be liftedWhat the host's policy is for lifting it; they differ

04What not to do

These are the reactions people reach for first, and each one costs time without helping.

ReactionWhy it fails
Blocking attacking IPsThousands of sources, rotating constantly; in reflection attacks they are innocent third parties
Rebooting the serverIt comes back up into the same flood, having lost whatever was still working
Blocking a whole countryAttacks are global; you mostly block customers
Turning off the siteThat is the attacker's goal, achieved manually
Scaling up the serverVolumetric attacks saturate the link, which more CPU does not widen
Switching protection off the moment it goes quietAttacks often come back in waves, and the next one lands on an unprotected origin
Paying a ransomMarks you as a target that pays, and rarely ends it

05Afterwards, before the next one

Attacks recur, frequently against the same target and often shortly after. The window right after one ends is the only time you will have both the motivation and the calm to prepare properly.

  • Keep protection always-on rather than switching it on when something breaks: Cloudflare's report for the first half of 2026 found that 90.6% of network-layer attacks were over within ten minutes, faster than anyone can react by hand; how long DDoS attacks last has the wider data
  • Audit every DNS record for anything still pointing at the origin, including subdomains you forgot; a DNS lookup of each name shows what the rest of the world sees
  • Check certificate transparency logs for certificates issued to hostnames that resolve to your origin — the logs are public and append-only, so anything there stays findable
  • Move mail off the web server, or its headers publish the address you just hid
  • Write down what the traffic looked like: source spread, request pattern, which endpoints were targeted
  • Report serious or repeated attacks: DDoS attacks are a criminal offence in most jurisdictions, and timestamps plus logs make a report usable
  • Set alerts on your own baseline, not on fixed thresholds

06Match the defence to the layer

A single answer does not cover every attack type, and buying the wrong one is a common and expensive mistake.

AttackWhat actually stops it
Volumetric floodUpstream capacity — absorbed before your uplink
SYN or protocol floodFiltering at the edge, plus SYN cookies, which avoid holding state for half-open connections
HTTP floodRequest inspection and challenges, not packet filtering; on a server you run, nginx limits and caching buy headroom
Slow attacks such as SlowlorisConnection timeouts and limits at the proxy
UDP flood on a game serverRouted transit with real UDP filtering, not null-routing

Questions

Frequently asked questions

Most are short. Cloudflare's report for the first half of 2026 found that 90.6% of network-layer attacks ended in under ten minutes, and some record-sized ones lasted well under a minute. Sustained multi-day campaigns exist and usually indicate a specific motive rather than opportunism.

Partially. Connection limits, caching and sensible rate limits genuinely help against small attacks. What you cannot do yourself is absorb a volumetric flood, because it saturates your uplink before any of your equipment sees it.

Only when a handful of addresses account for most of the traffic, which is rare. In a reflection attack the sources are innocent servers being abused, and in a botnet attack they rotate faster than a block list can grow. The capture is more useful for telling you what kind of attack it is.

For a serious or repeated attack, yes — it is a criminal offence in most jurisdictions, and reports contribute to cases against booter operators. It will not restore service, so do it in parallel with mitigation rather than instead of it.

They will tell you what they see, which is valuable. Many will also null-route your address to protect their own network, which stops the flood reaching them and leaves you just as offline — worth knowing in advance.

For a website, as fast as DNS propagates — minutes if your TTL was already low, hours if it was not. Lowering TTL is worth doing before you need it.

Sources

Sources and verification

nftables ruleset syntax-checked with nft 1.0.6, loaded twice in an isolated network namespace and tested over a veth pair (a listed source reached port 80, an unlisted source was dropped and counted). Debian 12, October 2026.

  1. 01DDoS threat report for 2026 H1 (attack duration) · Cloudflare
  2. 02RFC 4987: TCP SYN Flooding Attacks and Common Mitigations · IETF
  3. 03RFC 7999: BLACKHOLE Community · IETF
  4. 04How Certificate Transparency works · certificate.transparency.dev

Last updated