Security

How to Fix a DDoS Attack: How It Works and How to Mitigate It

To fix a DDoS attack, first confirm that the traffic really is an attack, then ask your hosting provider or ISP to filter it upstream, because you cannot drop traffic that has already filled your connection. After that, put a DDoS protection service in front of the site and tune your own server so it survives what gets through.

This guide is for people who run a website, game server or other public service and are seeing it go down under a flood of traffic. If you are a home user whose own connection is being flooded, the same logic applies: call your ISP, and as a last resort restart your router to try for a new public address.

What a DDoS attack is

A denial-of-service (DoS) attack tries to make a service unusable. In a distributed denial-of-service (DDoS) attack, the traffic comes from many machines at once, often computers and devices that an attacker has taken over. Because the requests come from thousands of different addresses, you cannot solve it by blocking one source. The UK National Cyber Security Centre frames the topic as a risk to manage: its guidance exists to "help organisations understand and manage the risk of denial of service (DoS) attacks", and it groups the practice into four steps: understand your service, understand your defences, create a response plan, and test your response.

Step 1: Confirm it is an attack

Not every outage is a DDoS. A popular link, a broken deployment or an exhausted database connection pool can look the same from the outside. Before you escalate, check for these signs:

  • Traffic spikes with no explanation. Requests per second or bandwidth jump far above your normal peak, with no launch, mention or campaign behind it.
  • Repetitive requests. Your access logs show the same URL, the same user agent or the same pattern thousands of times, often from addresses spread across many networks.
  • Half-open connections piling up. Many connections stuck in the SYN-RECEIVED state suggest a SYN flood (explained below).
  • The server itself is idle. If your link is saturated but CPU and memory are low, the problem is volume arriving at the network edge, not your application.

If the traffic is legitimate but too heavy, the fix is capacity and caching, not filtering. Be careful here, because blocking real users during a genuine surge is its own outage.

Step 2: Call upstream

The most effective fix for a large flood is outside your control, which is why contacting your provider comes first. If the attack is bigger than your internet link, your server never sees the packets it would need to drop. Your hosting provider, data centre or ISP can filter or reroute the traffic before it reaches you, and many offer this as a standard or paid service. Tell them when it started, which IP addresses are targeted, and what the traffic looks like. If you have no provider with that capability, move to Step 3.

The standard defence against floods that use forged sender addresses is ingress filtering, described in RFC 2827 (also known as BCP 38). The RFC asks every internet provider to accept traffic from a downstream network only if its source address belongs to a prefix that network legitimately uses, and to drop and log everything else. It calls for this "as soon as possible", and it asks corporate network administrators to apply the same filtering so their own networks do not become a source of attacks. This is something you ask your provider about, not something you configure on a web server.

Step 3: Put a protection service in front of the site

A DDoS protection or content delivery network sits between the internet and your server, so the attack traffic lands on its large network instead of yours. Cloudflare is one example: its documentation says its managed rulesets protect "across layers 3/4 (network layer) and layer 7 (application layer)", and that standard, unmetered DDoS protection is included on every plan. Its adaptive rules differ by plan, with the free through Enterprise plans including only error-based adaptive rules, and only the Enterprise add-on including all of them. That means a free plan is not equal to a paid one, so read what your plan actually includes (as of November 2026).

Two practical points apply to any such service. First, route all traffic through it. If attackers can still reach your server's real IP address directly, they will bypass the protection, so restrict your server to accept web traffic only from the service's address ranges, which the provider publishes. Second, you may need to change your DNS records to point at the service, and DNS changes take time to spread, so do this before the next attack, not during it.

Step 4: Harden the server against common floods

Some floods target the server software rather than the link. The best-documented is the TCP SYN flood. RFC 4987 describes it: an attacker sends many connection requests, often with spoofed source addresses, and the server allocates state for each half-open connection until its queue fills and real clients cannot connect. The RFC lists these defences, and it makes no standards-level recommendations about which to choose:

DefenceWhat it doesTrade-off noted in RFC 4987
FilteringBlocks spoofed source addresses at the networkHosts should not rely on it alone
Larger backlogMakes the half-open queue biggerLarge backlogs have scaling problems
Shorter SYN-RECEIVED timerDrops half-open entries soonerCan cut off some legitimate clients, and attackers just send more
SYN cacheStores minimal state until the handshake completesBucket limits apply
SYN cookiesEncodes state in the reply so none is kept until the handshake completesConflicts with some TCP options, such as window scaling
Firewalls and proxiesComplete the handshake on another device before forwardingNeeds a device that can handle the load

Most modern operating systems already include some form of SYN protection, so check your system's documentation for the exact setting name before changing anything. Do not copy tuning values from forum posts without testing them, because the wrong timer or backlog can make things worse.

For application-layer floods, such as thousands of requests to a search page or login form, limit what one client can do. Our article on what rate limiting is and how it works covers the mechanics, and a firewall on the server drops traffic to ports you never meant to expose. Also cache what you can: a page served from a cache costs far less than one built from a database query on every hit.

Step 5: Make a plan before the next one

The NCSC guidance lists "Create a response plan" and "Test your response" as separate practices for a reason: during an attack there is no time to work out who to call. Write down, ahead of time:

  • Who at your hosting provider or ISP to contact, and how to reach them out of hours.
  • Which services are critical, so you can switch off the rest to save capacity.
  • What normal traffic looks like, so you can spot a spike quickly. Without a baseline you cannot tell an attack from a good day.
  • How to change DNS or switch on stricter protection modes at your protection service.

Then rehearse it. A plan that has never been tried tends to fail on a missing password or an expired account.

What not to do

  • Do not try to hit back. The sources are usually hijacked machines belonging to uninvolved people, and attacking them is illegal in most places.
  • Do not block whole countries by reflex. Attack traffic is spread across the world, so it rarely helps and it locks out real users.
  • Do not pay a ransom. Payment does not guarantee the attack stops. Report the demand to your provider and the relevant authorities.
  • Do not ignore the logs afterwards. Keep them. Your provider can use them to tune filtering, and you can use them to build your baseline.

If it keeps coming back

Repeat attacks usually mean the weak point is still exposed. Check that the origin IP is hidden behind your protection service, that no old DNS record or mail server reveals it, and that your most expensive pages are cached or rate limited. If your service is business-critical, an always-on protection plan with a response agreement is a better fit than reacting each time.

Frequently asked questions

Can you stop a DDoS attack yourself?
Rarely, if the attack is large. A flood that fills your internet connection is already doing its damage before traffic reaches your server, so the filtering has to happen upstream, at your host, your ISP or a DDoS protection service. What you can do yourself is confirm the attack, call upstream, and reduce the load your own software puts on itself.
How long does a DDoS attack last?
There is no fixed length. Some attacks stop after minutes and others come back in waves, so do not assume the first quiet period means it is over. Keep monitoring and keep the mitigation in place until your traffic graphs have been normal for a good while.
Is a DDoS attack the same as a hack?
No. A DDoS attack only tries to make a service unavailable by overwhelming it with traffic. It does not by itself give the attacker access to your data. Attackers do sometimes use an outage as a distraction, so it is still worth checking your logs for other activity.
Does a firewall stop DDoS attacks?
A firewall on your own server helps against simple floods and unwanted ports, but it sits behind your internet link. If the traffic is large enough to saturate that link, the firewall never gets a chance to drop it. Large attacks need filtering upstream of your link.

Sources