---
title: "DDoS Attacks: What They Are and How to Defend Against Them"
domain: cybersecurity
level: intermediate
duration: "55 min"
objectives:
  - "Explain what denial-of-service (DoS) and distributed denial-of-service (DDoS) attacks are, and why attacks from botnets are hard to block."
  - "Classify DDoS attacks as volumetric, protocol or application-layer attacks, and give an example of each."
  - "Explain how reflection and amplification attacks work and why source address spoofing makes them possible."
  - "Compare DDoS defences (overprovisioning, rate limiting, SYN cookies, web application firewalls, anycast and CDNs, scrubbing services, blackholing) and choose the right one for each attack type."
  - "Plan a DDoS response: traffic baseline, detection, runbook and escalation to the provider."
---

# DDoS Attacks: What They Are and How to Defend Against Them

## Why this matters
An online shop makes most of its money in the week before a holiday. On Tuesday at 10:00 the site becomes slow, then stops answering. The servers are healthy, nothing was hacked, no data was stolen. The network link is simply full of traffic that nobody asked for, and real customers can't get in. The team doesn't know whether this is an attack or a successful advertising campaign, nobody knows the phone number of the hosting provider's security desk, and every hour offline costs sales and trust.

That is a **distributed denial-of-service (DDoS)** attack: the goal is not to break in but to make a service unavailable. Attacks like this are cheap to start (the services that sell them are illegal, but they exist), they are hard to block because the traffic comes from thousands of places, and no single product stops all of them. What does work is to understand which resource each attack exhausts, put the right defence at each layer, and have a written plan before the day it happens.

This lesson explains what DoS and DDoS attacks are, how botnets make them hard to block, the three classes of attack, how reflection and amplification turn other people's servers into weapons, the defences for each layer and how to respond. The lab then lets you flood your own web server in an isolated sandbox and defend it with rate limiting.

> [!IMPORTANT]
> This module is defensive. Flooding a system you don't own is a crime in most countries, even if you call it a "test". You only attack your own containers, on an isolated network. The lesson describes attacks conceptually, so you can recognise and stop them; it gives no instructions to launch one.

## Learning objectives
- Explain what denial-of-service (DoS) and distributed denial-of-service (DDoS) attacks are, and why attacks from botnets are hard to block.
- Classify DDoS attacks as volumetric, protocol or application-layer attacks, and give an example of each.
- Explain how reflection and amplification attacks work and why source address spoofing makes them possible.
- Compare DDoS defences (overprovisioning, rate limiting, SYN cookies, web application firewalls, anycast and CDNs, scrubbing services, blackholing) and choose the right one for each attack type.
- Plan a DDoS response: traffic baseline, detection, runbook and escalation to the provider.

## Key concepts

### DoS, DDoS and botnets
Picture a small restaurant with 20 seats. One rude person who sits down and never orders takes one seat. That is a nuisance. Now 500 people walk in at the same time, order nothing and refuse to leave: real customers can't get a table, and you can't throw out 500 people one by one. The first case is a DoS attack, the second a DDoS attack.

A **denial-of-service (DoS)** attack makes a service unavailable to its legitimate users by exhausting a resource: bandwidth, memory, processor time, connection slots, or the time of a human operator. It can come from a single machine, or even from one malformed request that crashes a buggy program. A **distributed denial-of-service (DDoS)** attack does the same from many machines at once. The "distributed" part is what makes it hard to stop.

Where do thousands of machines come from? Mostly from a **botnet**: a network of ordinary devices (a **bot**, or zombie, is each infected device) taken over with malware and controlled remotely from a **command-and-control (C2)** server. The owners usually notice nothing. Internet Protocol (IP) cameras, home routers, video recorders and other Internet of Things (IoT) devices are favourite targets: they are always on, always connected, rarely updated, and often still have the default password. The **Mirai** botnet of 2016 is the classic historical example. It scanned the Internet for IoT devices that accepted default credentials, enlisted them, and was used for some of the largest attacks of its time, including one on the Domain Name System (DNS) provider Dyn that made many well-known sites hard to reach for hours. Its source code was later published, and variants followed.

Attackers need no botnet of their own. **DDoS-for-hire** ("booter" or "stresser") services rent attack capacity for a small price. They are illegal, and law enforcement agencies have repeatedly taken them down, but their existence means that the skill and money needed to start an attack are low, so any public service can become a target, whether the reason is extortion, a grudge, competition, politics, or simply boredom.

![A botnet floods one target while a real customer is locked out. On the left, a botmaster controls a C2 server, which sends orders to a botnet of six compromised devices: an IP camera, a home router, a laptop, a video recorder, a phone and a hacked server. A thick line carries a flood from thousands of addresses to the target service at 203.0.113.80 on tcp 443. A real customer at 198.51.100.25 cannot get through, shown by a dashed red line with a cross.](../../../assets/diagrams/ddos-botnet.svg)

*Figure 1. Each bot sends only a little traffic, but together they bury the target, and the real customer is locked out.*

**Why blocking IP addresses doesn't scale.** The usual reflex is "block the attacker's address". Against a single source that works. Against a botnet it fails for four reasons:

- **Too many sources.** A botnet can have tens of thousands to millions of devices. A firewall list that long is slow, and by the time you finish, the botnet has changed.
- **Each source looks harmless.** If 100,000 bots send one request every few seconds, every address is below any sensible threshold. The harm is only in the sum.
- **The sources are real people's devices.** Many are home users, often in the same countries as your customers, so blocking whole networks blocks customers too.
- **The traffic may already have done its damage.** If the link is full, a rule on your firewall comes too late: the packets filled the pipe before they reached the firewall.

So you don't win a DDoS by blocking addresses at the end of the line. You win by absorbing the traffic where there is enough capacity, filtering by behaviour rather than by address, and keeping the service cheap enough to run that the attack costs more than it gains.

> [!CHECK]
> Why is blocking the attacker's IP addresses on your own firewall a poor main defence against a botnet?
>
> - [ ] Firewalls can't block IP addresses at all.
> - [x] There are too many sources, each one looks harmless alone, and a full link is already lost before the firewall sees the packets.
> - [ ] Botnets always use the same few addresses, which firewalls can't see.
> - [ ] Blocking addresses is illegal for companies that suffer an attack.
>
> A botnet spreads a large attack over thousands of ordinary-looking addresses, and the bandwidth is exhausted before your firewall can act. Blocking works well against one noisy source, not against many quiet ones.

### The three classes of DDoS attack
Every attack exhausts something. The useful question is *what*, because the answer tells you where to defend. The usual classification has three classes, each measured in a different unit.

**Volumetric attacks** fill the **bandwidth**: the pipe between you and the Internet. Traffic you never asked for, such as a flood of User Datagram Protocol (UDP) packets or reflected responses, arrives faster than the link can carry, so legitimate packets are dropped with the rest. The unit is **bits per second (bps)**, usually Gbps or Tbps. If the pipe is full, nothing you configure behind it can help, because the damage is done before the traffic reaches you.

**Protocol attacks**, also called **state-exhaustion attacks**, exhaust the **tables and counters** of devices that keep state: servers, firewalls and load balancers. The classic example is the **SYN flood**, described in [How it works](#how-it-works). Each packet is tiny and the bandwidth looks normal, but the device runs out of memory or connection slots. The unit is **packets per second (pps)**, because the work a device does is mostly per packet, not per byte.

**Application-layer attacks** target the **application**, at layer 7: CPU, database, threads, application connections. An **HTTP flood** sends valid-looking Hypertext Transfer Protocol (HTTP) requests, preferably for expensive pages such as search or report generation, so the server works hard for each one. **Slowloris** and other **slow attacks** open many connections and send them very slowly (a few header bytes every few seconds) so the server keeps each connection reserved until it has none left for real users. The unit is **requests per second (rps)**. These attacks need very little bandwidth and look like real users, so they are the hardest to tell apart from a busy day.

| Class | Layer | Example | What runs out | Measured in | Where you defend |
|---|---|---|---|---|---|
| Volumetric | 3–4 | UDP flood, reflection | Bandwidth | bps | Upstream: provider, content delivery network (CDN), scrubbing |
| Protocol | 4 | SYN flood | State tables | pps | SYN cookies, limits, load balancers |
| Application | 7 | HTTP flood, Slowloris | CPU, database, connections | rps | Rate limits, web application firewall (WAF), caching |

Real attacks often mix classes: a large volumetric flood to distract, with a quieter application attack underneath. Plan for combinations.

![Three classes of DDoS attack compared. Volumetric attacks work at layers 3 and 4, for example UDP floods and reflection, fill the bandwidth, are measured in bits per second and are absorbed upstream. Protocol attacks work at layer 4, for example a SYN flood, fill state tables, are measured in packets per second and are handled with SYN cookies, limits and load balancers. Application-layer attacks work at layer 7, for example HTTP floods and Slowloris, use up CPU, database and threads, are measured in requests per second and are handled with rate limits, a web application firewall, bot challenges and caching.](../../../assets/diagrams/ddos-attack-classes.svg)

*Figure 2. Same goal, three different resources: the unit of measure tells you which class you are facing.*

> [!NOTE]
> Records for the largest attacks keep being broken, and the exact numbers depend on who measures them and how. This lesson gives no figures for them. For the current picture, read the yearly threat reports that large providers publish. What matters here: attacks above one terabit per second exist, so no single site can absorb them alone.

> [!CHECK]
> A web site has plenty of bandwidth, but its search page is slow and the database CPU is at 100%. Access logs show thousands of normal-looking `GET /search?q=...` requests per second. Which class is this?
>
> - [ ] Volumetric, because there are thousands of requests.
> - [ ] Protocol, because it uses TCP.
> - [x] Application-layer: each request is cheap to send and expensive to answer.
> - [ ] Reflection, because the requests look normal.
>
> Bandwidth is fine, the exhausted resource is the application's CPU and database, and the unit is requests per second. That is an HTTP flood.

### Reflection and amplification
Some attacks use other people's servers as weapons. Think of ordering catalogues: you write to a hundred companies "please send your big catalogue to this address", and you put your victim's address on the return line. You spend 100 stamps and the victim receives 100 heavy parcels. The companies did nothing wrong. They answered a request that looked ordinary.

In a **reflection attack**, the attacker sends a request to a third-party server (the **reflector**) with a **spoofed source address**: the packet claims to come from the victim. The reflector replies to the source address it sees, so the reply goes to the victim, and the attacker's real address never appears. This works for UDP-based services because UDP has no handshake: nothing checks that the sender really owns the source address. (The handshake of the Transmission Control Protocol (TCP) makes this hard, because the attacker would have to see the reply to continue.)

It becomes **amplification** when the reply is much bigger than the request. The **amplification factor** is response size divided by request size: with a factor of 50, an attacker who can send 100 Mbit/s of spoofed requests causes 5 Gbit/s to arrive at the victim. The attacker multiplies a small amount of own bandwidth into a large attack, and hides behind the reflectors.

Services that have been abused as reflectors are those that answer small UDP queries with large answers and, in the past, to anyone:

| Reflector | Port | Why it amplifies |
|---|---|---|
| **Open DNS resolver** | udp 53 | A short query for a record with a large answer (many records, or DNS Security Extensions (DNSSEC) data) returns a big response |
| **NTP `monlist`** | udp 123 | An old command on older Network Time Protocol (NTP) servers returned a list of up to hundreds of recent clients |
| **Memcached** | udp 11211 | A cache server with UDP enabled and exposed to the Internet can return very large stored values for a tiny request |
| **CLDAP** | udp 389 | Connectionless Lightweight Directory Access Protocol (LDAP) answers to a small query with a large directory entry |

> [!NOTE]
> Amplification factors depend on the server's configuration and the query used, so published values differ. As an order of magnitude, from the public advisories: DNS tens of times, NTP `monlist` hundreds of times, memcached tens of thousands of times. Don't treat these as exact figures. The memcached attacks of early 2018 were, at the time, the largest ever recorded, which is why they are cited so often.

![Reflection and amplification with a spoofed source address. The attacker at 192.0.2.66 sends a small request whose source address is spoofed as the victim's address, 203.0.113.80. It passes the attacker's Internet service provider (ISP), which has no ingress filter (BCP 38 would drop the packet here), and reaches open reflectors: a DNS resolver at 198.51.100.53 on udp 53 and NTP, memcached and CLDAP servers on udp 123, 11211 and 389. Each reflector sends a much larger response to the victim, shown by a thick red line.](../../../assets/diagrams/ddos-reflection.svg)

*Figure 3. A small spoofed request becomes a large response aimed at the victim. The root fix is at the attacker's network, where the spoofed packet should never have left.*

**The root fix: BCP 38.** Spoofing is possible because the attacker's network lets packets leave with a source address that doesn't belong to it. **Ingress filtering**, described in [RFC 2827](https://www.rfc-editor.org/rfc/rfc2827) (also known as **BCP 38**, a Best Current Practice), means that a network edge drops any packet whose source address isn't in the range assigned to that customer. If every network did it, spoofed reflection attacks would not work. Unfortunately it protects other people's networks more than your own, so adoption is incomplete. [RFC 3704](https://www.rfc-editor.org/rfc/rfc3704) (BCP 84) extends it to networks with several providers. What you can do: filter on your own network edge so you never become the source of spoofed traffic, and choose providers that do.

> [!CHECK]
> Why can an attacker aim a reflection attack at a victim without the victim ever seeing the attacker's real address?
>
> - [ ] The attacker encrypts the packets, so the victim can't read the source.
> - [x] The attacker spoofs the victim's address as the source, so the reflectors answer the victim, and the attacker's network doesn't filter spoofed sources.
> - [ ] The reflectors hide the sender's address on purpose, to protect their users.
> - [ ] The victim's firewall removes the attacker's address from the logs.
>
> UDP services answer the source address they see, and without BCP 38 ingress filtering nothing stops a network from sending packets with a false source address.

### Defences by layer
No single tool stops every attack, because each attack class exhausts something different. A good defence is layered, so each layer removes what the next one could not afford to see. The closer to the attacker the layer is, the bigger the attack it can absorb.

![Layered DDoS defence from the provider to the application. Five numbered layers in a row. 1 Provider or ISP: scrubbing centre, with blackholing as a last resort, for volumetric and reflection attacks. 2 CDN and anycast: spread the load over many sites and cache, for volumetric attacks and HTTP floods. 3 Network edge: firewall and load balancer with SYN cookies and limits, for SYN floods. 4 Web server or WAF: rate limit, bot challenge and rules, for HTTP floods and Slowloris. 5 Application: cheap pages, caching, timeouts and queues, for expensive requests.](../../../assets/diagrams/ddos-layered-defence.svg)

*Figure 4. Five layers, from the provider to the application. Each is matched to the attack classes it stops.*

**Overprovisioning.** Buy more bandwidth and capacity than you need. It is simple and also helps with the legitimate surge of a marketing campaign. But its limits are clear: attackers can send more than you can afford, you pay for capacity that sits idle most of the year, and it does nothing against a small application-layer attack that exhausts a database. Treat it as the base layer, not the plan.

**Rate limiting and connection limits.** Cap how many requests (or new connections) a single client can make per time unit, and how many connections it can hold open at once. Everything above the cap gets a quick refusal, such as HTTP status `429 Too Many Requests`, which is much cheaper for the server than doing the real work. This is the main defence against application-layer floods and slow attacks, and it is what you build in the lab. Limits have weaknesses: a botnet where each bot stays below the limit passes through (you need global limits, per-page limits, and behaviour rules too), and many real users can share one address behind a carrier-grade network address translation (NAT) or a company proxy, so a strict per-address limit can punish them.

**SYN cookies.** A way to survive a SYN flood without keeping a table entry for every half-open connection. They are explained in [How it works](#how-it-works) and described in [RFC 4987](https://www.rfc-editor.org/rfc/rfc4987). Operating systems and load balancers include them.

**Web application firewall (WAF) and bot challenges.** A WAF inspects HTTP requests and blocks those matching rules or known bad patterns. Bot management goes further: it separates humans from scripts using a JavaScript or proof-of-work **challenge**, a CAPTCHA, or browser and behaviour signals, and rate-limits or blocks the scripts. These work at layer 7 and are your best tool against HTTP floods that look like real users.

**Anycast and content delivery networks (CDNs).** In **anycast**, the same IP address is announced from many locations, and the Internet's routing sends each client to the nearest one ([RFC 4786](https://www.rfc-editor.org/rfc/rfc4786) describes the practice). Attack traffic from a botnet is therefore split among many sites, each absorbing the part that is near its sources, instead of reaching one place. A **CDN** puts a worldwide network of caching servers in front of your origin: static content is served from the edge, and only the requests that need the origin reach it. A CDN also hides your origin address, which must then stay private and accept traffic only from the CDN.

**Scrubbing centres and provider or ISP protection.** A **scrubbing centre** is a facility with a very large capacity that receives your traffic, removes the attack traffic and sends back the clean traffic. Providers offer this as a service, either **always-on** (all traffic goes through it) or **on-demand** (traffic is redirected, usually by changing the routing announcements, when an attack starts). Large clouds and ISPs include basic protection, and many sell stronger tiers. Examples exist from several vendors, and the choice depends on your provider and size.

**Remotely triggered blackholing (RTBH).** The last resort. You ask your provider to drop all traffic to the attacked IP address, by tagging that address's route with the well-known **BLACKHOLE community**, 65535:666, defined in [RFC 7999](https://www.rfc-editor.org/rfc/rfc7999). The attack stops hurting the link and everything else on it. The trade-off is hard: **the attacker gets what they wanted for that address**, because the target is now unreachable for everybody, customers included. Blackholing saves the rest of your network, and it works best if the attacked address is not the only one your service uses. Think of it as sacrificing a room to save the house.

**Close the reflectors you operate.** Your servers can be somebody else's weapon. Don't run open DNS resolvers (restrict recursion to your own clients), disable the NTP `monlist` feature and restrict NTP queries, bind memcached to a local interface or disable its UDP port, and block unneeded UDP services such as CLDAP from the Internet at the edge. Combine with ingress and egress filtering (BCP 38) so your network can't send spoofed packets.

| Attack | First layer to use | Also |
|---|---|---|
| Volumetric flood or reflection | Provider or scrubbing service, anycast CDN | Blackholing as a last resort |
| SYN flood | SYN cookies, load balancer in front | Connection limits, scrubbing |
| HTTP flood | WAF, bot challenge, rate limits, CDN caching | Scrubbing with layer 7 filtering |
| Slow attack (Slowloris) | Short timeouts, per-address connection limit, reverse proxy | WAF |
| Reflection from your servers | Close open reflectors, filter spoofed sources | Monitoring |

> [!CHECK]
> You ask your provider to blackhole the one IP address under attack. What is the main trade-off?
>
> - [ ] The attack grows, because blackholing amplifies the traffic.
> - [ ] Only the attacker's traffic is dropped, so there is no trade-off.
> - [x] The rest of the network is protected, but the attacked address is unreachable for everyone, so the attack achieved its goal for that address.
> - [ ] The provider has to change your DNS records and it takes days.
>
> A blackhole drops all traffic to the address, good and bad. It is a last resort that saves the other services sharing the link.

### Respond: before, during and after
When the attack comes, you have no time to think about who to call. A DDoS response plan is mostly work done in advance.

![A DDoS response plan in six steps. 1 Baseline, before the attack: know normal traffic and capacity. 2 Detect, during: alerts on traffic, errors and latency. 3 Triage, during: is it an attack or a popular day? 4 Mitigate, during: follow the runbook and call the provider. 5 Communicate, during: status page, customers and managers. 6 Review, after: what worked, and update the runbook.](../../../assets/diagrams/ddos-response-plan.svg)

*Figure 5. The first step and the last decide most of the result: know what normal looks like before, and learn from the attack after.*

1. **Baseline (before).** Measure normal traffic: requests per second, bandwidth, new connections per second, error rate and latency, by hour and day of the week. Know your capacity: the number of requests your servers handle before they slow down, found by load-testing your own systems in a test environment. You can't see "abnormal" without "normal".
2. **Detect (during).** Alert on the symptoms: traffic or requests far above the baseline, a rise in 5xx errors, rising latency, a spike of connections in half-open state, a flood from few autonomous systems or countries you don't usually serve. Alert the right people at any hour.
3. **Triage (during).** Is it an attack or a legitimate surge (a campaign, a news mention, a product launch)? Look at the user agents, the pages requested, the geographic spread and whether the requests look like real sessions. Check which resource is exhausted (bandwidth, connection table, application CPU) to know the class and pick the defence.
4. **Mitigate and escalate (during).** Follow a **runbook**: a short written procedure of who does what in which order. Typical steps: enable stricter rate limits or a "under attack" challenge mode, move traffic to the scrubbing service, call the provider's security or support line (with the number and your account details already written in the runbook), and consider blackholing only for the single address if everything else fails.
5. **Communicate (during).** Tell customers and your own management early and honestly: a status page, a short note, an estimated next update. A clear message prevents panic and support overload. Keep a log of timestamps and actions.
6. **Review (after).** In a post-incident review (without blame), ask what you saw first, how long detection and mitigation took, what worked, what failed and what to change: thresholds, contacts, capacity, architecture. Update the runbook and test it.

> [!CHECK]
> Which preparation matters most for noticing a DDoS attack quickly and correctly?
>
> - [ ] Buying a second firewall of the same brand.
> - [ ] Publishing your server's real IP address in the DNS records.
> - [x] A traffic baseline with alerts, so abnormal traffic is visible and a busy day can be told from an attack.
> - [ ] Waiting for customers to report problems.
>
> Without a baseline you can't tell "abnormal" from "normal". Alerts on traffic, errors and latency turn the baseline into early detection.

## How it works
The SYN flood is the best example of a protocol attack, because it abuses how a normal TCP connection starts. If you need to refresh the three-way handshake, read [Networking 08 — Transport Layer: TCP, UDP and Ports](../../networking/08-tcp-udp/README.md).

**The half-open connection table.** A server that listens on a port does the following when a client sends a **SYN** (synchronize, the first message of the handshake): it records the new connection in a table, in the state `SYN_RECV` (also called half-open, because the handshake is not finished), and answers with a **SYN-ACK**. It then waits for the client's final **ACK** (acknowledgement). That wait is the weakness. The table has a limited size (the **listen backlog**), and an entry stays there until the ACK arrives or a timeout expires, which can take many seconds.

In a **SYN flood**, the attacker sends a very large number of SYN packets, often with random spoofed source addresses. The server answers each one with a SYN-ACK to an address that never asked for it, so the final ACK never arrives, and each half-open entry waits until its timeout. The table fills. When it is full, new SYNs, including those from real customers, are dropped. The bandwidth looks small and the server is not "busy", but it can't accept any new connection. Real bots do not even need to spoof: a botnet sending real SYNs does the same.

![A SYN flood fills the half-open connection table. An attacker with spoofed sources sends SYN packets from random source addresses to a server at 203.0.113.80 on tcp 443. The server's half-open connection table, the listen backlog, has a fixed number of slots and lists four entries in state SYN_RECV for the sources 203.0.113.7:51034, 198.51.100.9:40211, 192.0.2.200:33102 and 203.0.113.141:60977, marked full. Each entry waits for an ACK that never comes. A real customer at 198.51.100.25 sends a SYN that is dropped because no slot is free.](../../../assets/diagrams/ddos-syn-flood.svg)

*Figure 6. The attack costs the attacker almost nothing per packet, but each packet reserves a slot until its timeout.*

**SYN cookies.** [RFC 4987](https://www.rfc-editor.org/rfc/rfc4987) describes several mitigations (bigger backlog, shorter timeouts, filtering, and others) and, among them, **SYN cookies**. The idea: if the table is full, stop using it. The server answers the SYN with a SYN-ACK whose **sequence number is a cookie**: a value computed from the client's address and port, the server's address and port, a coarse timestamp and a secret that only the server knows. It stores **nothing**. A real client answers with an ACK that acknowledges "cookie + 1". The server recomputes the cookie from the packet and, if it matches, creates the connection at that moment. A spoofed sender never answers, so the attack no longer uses any table slot.

![How SYN cookies avoid keeping state during the handshake. Step 1: the client at 198.51.100.25 sends a SYN with sequence number x. The server at 203.0.113.80 stores nothing and computes a cookie from addresses, ports, a timestamp and a secret. Step 2: the server sends a SYN-ACK whose sequence number is the cookie and whose acknowledgement is x plus one. Step 3: the client sends an ACK that acknowledges the cookie plus one. The cookie checks out and only now is the connection created. A spoofed sender never answers, so no table slot is ever used.](../../../assets/diagrams/ddos-syn-cookies.svg)

*Figure 7. With SYN cookies the server keeps no state until the client proves it received the SYN-ACK.*

There is a cost: because the server remembers nothing, some TCP options negotiated in the SYN (such as the maximum segment size, window scaling and selective acknowledgements) must be squeezed into the cookie or may be lost, so the connection can be slightly less efficient. That is why many systems use cookies **only when the table is full**. Linux does this by default: the setting `net.ipv4.tcp_syncookies` has the value `1`, which means "use cookies only when the backlog overflows". You read it in the lab. A SYN flood that is big enough in packets per second can still saturate the CPU or the link, so SYN cookies are one layer, not the whole answer.

> [!CHECK]
> What does a server using SYN cookies do when a SYN arrives and its half-open table is full?
>
> - [ ] It drops the SYN so that the table can drain.
> - [ ] It blocks the source address for an hour.
> - [x] It answers with a SYN-ACK that carries a cookie, keeps no state, and creates the connection only if the returning ACK matches the cookie.
> - [ ] It asks the client to send the SYN again over UDP.
>
> The cookie encodes what the server would have stored, so the proof comes back with the client's ACK. Spoofed senders never reply, so they never take a slot.

## Worked example
You run a web site on `203.0.113.80`. Its normal traffic is about 40 requests per second at the busiest hour, and it stays healthy until about 300 requests per second, because every page needs a database query. This is your baseline and your capacity.

**1. Detection.** A monitoring alert fires at 10:02: "requests per second above 3 times the daily peak". The access log shows this:

```text
203.0.113.7    - - [07/Nov/2026:10:02:11 +0000] "GET /search?q=a HTTP/1.1" 200 5120 "-" "Mozilla/5.0"
198.51.100.9   - - [07/Nov/2026:10:02:11 +0000] "GET /search?q=b HTTP/1.1" 200 5120 "-" "Mozilla/5.0"
192.0.2.200    - - [07/Nov/2026:10:02:11 +0000] "GET /search?q=c HTTP/1.1" 200 5120 "-" "Mozilla/5.0"
```

**2. Triage.** Bandwidth is only 5% of the link, the SYN backlog is normal, and 90% of the requests are `/search`: the class is application-layer. Many addresses send a modest rate each, so a per-address ban won't solve it.

**3. Choose defences by class.** Because the resource at risk is the database, you (a) put a rate limit on `/search` in the web server or CDN, (b) turn on the CDN's challenge mode for that path, (c) cache popular search results for 30 seconds, and (d) open a ticket with the provider's DDoS team to tell them what you see, with the runbook's contact.

**4. Do the arithmetic for a rate limit.** In nginx (the web server used in the lab), the rule `rate=5r/s` with `burst=10` and `nodelay` lets one client address through with 10 immediate requests, then 5 more per second:

```nginx
limit_req_zone $binary_remote_addr zone=perip:10m rate=5r/s;

server {
    location /search {
        limit_req zone=perip burst=10 nodelay;
        limit_req_status 429;
    }
}
```

In `T` seconds, one address can make about `10 + 5 × T` successful requests. In 15 seconds that is `10 + 5 × 15 = 85`, no matter how many requests it sends. You check this number in the lab: the two simulated bots each got about 85 answers out of thousands of attempts. A person who clicks around gets 429 only if they exceed 5 requests per second.

**5. See the limit of the rule.** Suppose the attack comes from 10,000 addresses. Each is allowed `10 + 5 × 15 = 85` requests in 15 seconds, so together they still make 10,000 × 85 / 15 ≈ 56,700 requests per second on average over those 15 seconds, and 10,000 × 5 = 50,000 per second once the bursts are used up. Your capacity is 300. Per-address limits are necessary, but against a real botnet you also need a global limit, a challenge, caching and upstream capacity (CDN or scrubbing).

**6. Close the loop.** After the attack, the review finds that the alert fired after 2 minutes but the provider's phone number in the runbook was out of date. You fix it, lower the alert threshold and schedule a test of the procedure.

**A quick bandwidth calculation** shows why the units matter. A 1 Gbit/s link carrying the smallest Ethernet frames (64 bytes, plus 20 bytes of preamble and gap on the wire, 84 bytes in total) has room for `1,000,000,000 / (84 × 8) ≈ 1.49` million packets per second. A device that can only process 500,000 packets per second would be overwhelmed by small packets at about a third of the link speed: a *pps* problem, not a *bps* problem.

## Common pitfalls
- **Having the plan only in somebody's head** — the person who knows the provider's number is on holiday. Write the runbook, with contacts, and test it.
- **Trusting only one layer** — a firewall in front of a full link does nothing, and a CDN does nothing for an origin whose address is public and attackable directly. Cover each class.
- **Confusing a flash crowd with an attack** — blocking a successful campaign is also an outage. Check user agents, pages requested and referrers before blocking.
- **Setting limits without measuring normal traffic** — a limit too low blocks real users (especially those sharing one address), and one too high stops nothing. Base it on the baseline.
- **Blackholing too early** — it completes the attack for that address. Try scrubbing, filtering and rate limits first, unless the rest of your network is in danger.
- **Leaving the origin exposed behind a CDN** — if attackers find the origin's real address, they bypass the CDN. Restrict the origin to the CDN's address ranges and keep the address private.
- **Running an open reflector yourself** — an open DNS resolver or memcached with UDP exposed makes your server part of other people's attacks, and may get your network blocked.

## Security considerations
- **Legal and ethical limits.** Launching or renting a DDoS attack is a criminal offence in most countries, whatever the motive and whatever you call it ("test", "stress test", "joke"). Even a short flood against a shared host harms other customers of that host. Stress-test only systems you own, or with written authorization, and read your cloud provider's policy on load testing before you do it.
- **Don't be part of the problem.** Patch and password-protect IoT and other devices: default credentials are how botnets grow. Filter spoofed source addresses on your network edge (BCP 38). Close the reflectors you operate.
- **DDoS as a smokescreen.** Attackers sometimes use a flood to distract the security team while they do something else, such as intrusion or data theft. Keep watching the rest of your logs while you handle the attack.
- **Extortion.** Some attackers demand money to stop. Paying is discouraged by authorities because it funds more attacks and doesn't guarantee they stop. Follow your incident procedure and involve law enforcement and the provider.
- **Mitigation has costs.** Challenges can block assistive technologies and legitimate automation (for example an API client), rate limits can hurt shared addresses, and traffic redirected to a third-party scrubbing or CDN service passes through that provider, so check what it can see (it terminates Transport Layer Security (TLS), so it sees the content) and what your data protection obligations are.
- **Don't announce your capacity.** The numbers you set (limits, thresholds) belong in internal documents, not in public pages.

## Summary
- A DoS attack exhausts a resource; a DDoS attack does it from many machines at once, usually a botnet of compromised devices, so blocking addresses one by one doesn't scale.
- The three classes exhaust different things: volumetric attacks fill bandwidth (bps), protocol attacks fill state tables (pps), application attacks use CPU, database and connections (rps).
- Reflection and amplification turn open UDP services into weapons, thanks to spoofed source addresses. The root fix is BCP 38 ingress filtering (RFC 2827) and closing the reflectors you operate.
- Defend in layers: provider and scrubbing, CDN and anycast, SYN cookies and limits at the edge, rate limiting and a WAF at the web server, a cheap and cached application. Blackholing (RFC 7999) is a last resort that completes the attack for that address.
- Prepare before: a traffic baseline, alerts, a runbook with provider contacts. After the attack, review and improve.

## Glossary
| Term | Definition |
|---|---|
| Denial-of-service (DoS) | An attack that makes a service unavailable to its users by exhausting a resource |
| Distributed denial-of-service (DDoS) | A DoS attack launched from many machines at once |
| Botnet | A network of compromised devices (bots) controlled remotely by an attacker |
| Bot | One compromised device that follows the attacker's orders |
| Command-and-control (C2) server | The server through which an attacker sends orders to the bots in a botnet |
| Internet of Things (IoT) | Connected everyday devices such as cameras, routers and sensors, often weakly secured |
| Mirai | A botnet of 2016 made of IoT devices with default passwords, a historical example |
| DDoS-for-hire | Illegal services that rent out attack capacity, also called booters or stressers |
| Volumetric attack | An attack that fills the bandwidth of a link, measured in bits per second |
| Protocol attack (state exhaustion) | An attack that fills the state tables of servers, firewalls or load balancers, measured in packets per second |
| Application-layer attack | An attack on layer 7 that exhausts CPU, database or connections, measured in requests per second |
| SYN flood | A protocol attack that sends many TCP SYN packets to fill the half-open connection table |
| Half-open connection | A TCP connection where the server has answered the SYN but has not yet received the final ACK |
| Listen backlog | The limited queue where a server keeps half-open connections |
| HTTP flood | An application attack that sends a large number of valid-looking HTTP requests |
| Slowloris | A slow attack that holds many connections open by sending requests very slowly |
| Reflection attack | An attack that makes third-party servers send their replies to the victim by spoofing the victim's address |
| Reflector | A server (for example an open DNS resolver) that answers requests sent with a spoofed source |
| Amplification factor | The size of the response divided by the size of the request in a reflection attack |
| Source address spoofing | Sending packets with a false source IP address |
| Ingress filtering (BCP 38) | Dropping packets whose source address does not belong to the network they come from (RFC 2827) |
| Overprovisioning | Buying more capacity than normal traffic needs, to absorb surges |
| Rate limiting | Capping how many requests or connections one client can make per time unit |
| SYN cookies | A technique that encodes the connection state in the SYN-ACK sequence number so the server stores nothing until the ACK returns (RFC 4987) |
| Web application firewall (WAF) | A filter that inspects HTTP requests and blocks those that match its rules |
| Challenge (bot challenge) | A test, such as a CAPTCHA or a script, that tells humans from automated clients |
| Anycast | Announcing the same IP address from many locations so each client reaches the nearest one |
| Content delivery network (CDN) | A worldwide network of caching servers placed in front of an origin server |
| Scrubbing centre | A high-capacity facility that removes attack traffic and returns clean traffic |
| Remotely triggered blackhole (RTBH) | Asking the provider to drop all traffic to one IP address, using the BLACKHOLE community (RFC 7999) |
| Runbook | A short written procedure that says who does what, in what order, during an incident |
| Baseline | The measured normal level of traffic, errors and latency |

## Check your understanding
1. Why is a botnet attack from 50,000 addresses harder to stop than the same volume from one address, even if your firewall can block addresses?
2. A customer says your site is down. Bandwidth is at 3%, but the connection table of your load balancer is full. Which class of attack is this and which defence fits first?
3. An open resolver you forgot about is used in a reflection attack. Who receives the traffic, who suffers a cost, and what should be configured to prevent it?
4. What are the advantages and the limits of per-address rate limiting? When does it fail?
5. Write the five lines that must be in a DDoS runbook's first page.

## References
- [RFC 4987](https://www.rfc-editor.org/rfc/rfc4987) — TCP SYN Flooding Attacks and Common Mitigations
- [RFC 2827 (BCP 38)](https://www.rfc-editor.org/rfc/rfc2827) — Network Ingress Filtering: Defeating Denial of Service Attacks which employ IP Source Address Spoofing
- [RFC 3704 (BCP 84)](https://www.rfc-editor.org/rfc/rfc3704) — Ingress Filtering for Multihomed Networks
- [RFC 4786 (BCP 126)](https://www.rfc-editor.org/rfc/rfc4786) — Operation of Anycast Services
- [RFC 7999](https://www.rfc-editor.org/rfc/rfc7999) — BLACKHOLE Community
- [RFC 9293](https://www.rfc-editor.org/rfc/rfc9293) — Transmission Control Protocol (TCP)
- [CISA: Understanding and Responding to DDoS Attacks](https://www.cisa.gov/resources-tools/resources/understanding-and-responding-distributed-denial-service-attacks)
- [nginx documentation: ngx_http_limit_req_module](https://nginx.org/en/docs/http/ngx_http_limit_req_module.html)
