What are DDoS Attacks? How to Prevent DDoS Attacks?

What are DDoS Attacks? How to Prevent DDoS Attacks?

A distributed denial of service attack strikes directly at service availability. Unlike credential theft or code injection vulnerabilities, denial of service attacks do not attempt to crack database tables or compromise system files. When production servers absorb tens of thousands of spoofed packets or millions of malicious HTTP requests per second, CPU queues saturate, network buffers overflow, connection tracking tables exhaust allocations, and users encounter dropped connections.

For hosting environments, SaaS platforms, and digital storefronts, downtime carries immediate financial consequences. When transit carriers detect unmitigated volumetric traffic, they enforce BGP null-routing, or blackholing. Blackholing drops all incoming traffic to the victim IP address at the carrier level, taking the service completely offline. Defending production systems demands a multi-tiered strategy spanning upstream edge scrubbing, transport tuning, and host kernel hardening.

The Technical Anatomy and Taxonomy of DDoS Attacks

Denial of service operations exploit characteristics across the OSI stack, dividing into three primary categories based on their target layer.

1. Volumetric Attacks (Network Layers 3 and 4)

Volumetric attacks seek to consume all available bandwidth between the target host and the upstream provider, measured in Gigabits per second (Gbps). The objective is simple: saturate physical network interface cards or upstream transit switches.

Attackers generate massive volume using reflection and amplification across stateless UDP services:

  • DNS Amplification: Attackers send ANY queries with spoofed source IPs to open recursive resolvers. A 60-byte query triggers DNSSEC responses exceeding 3,000 bytes, yielding a 50x multiplier.
  • NTP Monlist Amplification: Older Network Time Protocol daemons support the monlist diagnostic query, returning the last 600 client IPs with amplification exceeding 200x.
  • SSDP and SNMP Reflection: Exploits exposed IoT devices and misconfigured switches to generate high-bandwidth reflection streams.
  • Memcached Exploitation: Exposed Memcached instances on UDP port 11211 produce amplification reaching 51,000x, generating multi-terabit floods.

2. Protocol and State-Exhaustion Attacks (Layers 3 and 4)

Protocol attacks target state tables and connection buffers within firewalls, load balancers, and operating system kernels, measured in Packets Per Second (PPS).

The baseline protocol attack is the TCP SYN Flood. Standard TCP handshakes require a three-way exchange: SYN, SYN-ACK, and ACK. In a SYN flood, the attacker transmits continuous SYN packets with spoofed source addresses. The host allocates memory in its backlog queue (tcp_max_syn_backlog) and waits for final ACKs until socket timeouts occur, rapidly exhausting connection slots and dropping genuine visitors.

Other protocol vectors include ACK Floods, which force inspection engines to exhaust processor cycles scanning conntrack tables for nonexistent sessions, and IP Packet Fragmentation, which floods hosts with malformed UDP or ICMP fragments that exhaust memory buffers during reassembly attempts.

3. Application Layer Attacks (Layer 7)

Layer 7 attacks target the software stack handling web traffic, such as Nginx, Apache, PHP-FPM, and SQL databases. Measured in Requests Per Second (RPS), these attacks mimic genuine users, bypassing standard L3/L4 firewalls:

  • HTTP/HTTPS Floods: Generating thousands of concurrent GET or POST requests against dynamic, un-cached endpoints or complex database search routines.
  • Slowloris: Opening hundreds of connections and transmitting incomplete HTTP headers slowly (e.g., one line every 15 seconds), exhausting server worker processes like Apache’s MaxRequestWorkers.
  • Slow POST: Sending valid Content-Length headers but transmitting message bodies at one byte every few seconds, tying up worker threads indefinitely.
  • TLS Negotiation Exhaustion: Repeatedly initiating encrypted handshakes without completing sessions, overloading server cryptographic hardware.

How Modern DDoS Mitigation Infrastructure Operates

Mitigating large attacks requires filtering traffic before it reaches single-node hosting boundaries. A single server provisioned with a 1 Gbps uplink cannot withstand a 50 Gbps flood regardless of kernel optimization. Defending at scale requires distributed network architecture.

Anycast BGP Routing and Scrubbing Centers

Modern defense begins with Border Gateway Protocol (BGP) Anycast routing. Under Anycast, the same IP prefix is announced simultaneously from multiple geographically dispersed data centers. Routing protocols direct attack traffic to the nearest regional Point of Presence (PoP), dividing a 500 Gbps worldwide attack into manageable regional streams of 20 to 30 Gbps.

Within regional facilities, dedicated scrubbing hardware examines incoming packets in real time. Inspection engines apply deep packet inspection and heuristic filtering. Malicious packets are discarded at wire speed using field-programmable gate arrays (FPGAs), while verified traffic travels through Generic Routing Encapsulation (GRE) tunnels or direct cross-connects to the origin server.

Reverse Proxy and Edge Shielding

For application-layer protection, reverse proxies terminate TCP and TLS connections at edge nodes. Edge servers inspect HTTP headers, evaluate TLS fingerprinting parameters (JA3/JA4), challenge suspicious sessions, and serve static assets from edge caches. Origin servers only process verified dynamic requests.

Organizations operating critical infrastructure through DDoS protected dedicated servers benefit from hardware-level upstream filters that continuously screen ingress packets before they hit physical network switch ports.

Host-Level Hardening: Linux Kernel Network Stack Optimization

While upstream scrubbing absorbs massive volumetric floods, origin servers must withstand protocol attacks and burst spikes that reach the operating system. Modifying kernel network settings via /etc/sysctl.conf improves packet survival rates.

1. Activating and Tuning TCP SYN Cookies

When the SYN backlog queue fills up, standard Linux behavior drops new connection requests. Enabling SYN cookies alters this process: instead of storing connection state in memory, the kernel encodes connection state into the initial sequence number of the SYN-ACK packet. When the client returns the final ACK, the kernel cryptographically recalculates the sequence number and instantiates the socket.

Apply the following production parameters to /etc/sysctl.conf:

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 10000
net.core.somaxconn = 8192
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1

Load these configurations into the running kernel without rebooting:

sudo sysctl -p

2. Conntrack Management and Stateless Bypassing

Linux firewalls rely on Netfilter’s connection tracking subsystem (nf_conntrack). During intense stateful floods, this table fills rapidly. Once full, the kernel drops all incoming packets, including legitimate connections.

sysctl net.netfilter.nf_conntrack_count
sudo sysctl -w net.netfilter.nf_conntrack_max=524288

For high-throughput web frontends handling thousands of packets per second, configure stateless packet processing in iptables or nftables for traffic on ports 80 and 443 using the NOTRACK target in the raw table, bypassing the conntrack engine completely.

3. Kernel-Bypass Packet Filtering with eBPF and XDP

Traditional firewall rules evaluated within iptables require the Linux kernel to allocate a socket buffer (sk_buff) for every incoming packet. Processing millions of malicious packets per second saturates CPU cores with software interrupts.

Modern Linux deployments use eXpress Data Path (XDP) powered by eBPF. XDP executes custom packet-filtering bytecode directly within the network interface driver layer before the kernel allocates memory or creates socket buffers. Malicious packets that match blacklisted IP ranges or flood signatures drop immediately at the driver level, allowing a single CPU core to filter over 15 million packets per second.

Web Server Layer Hardening (Nginx Configuration)

Origin servers running behind reverse proxies or hosting applications directly on high-performance VPS hosting solutions must limit abusive requests at the application tier. Nginx provides rate limiting and connection limiting modules.

Configuring Nginx Rate Limiting and Timeout Rules

Open /etc/nginx/nginx.conf and configure request zones inside the http block:

http {
    limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=15r/s;
    limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;

    server {
        listen 80;
        listen 443 ssl http2;
        server_name example.com;

        client_body_timeout 10s;
        client_header_timeout 10s;
        keepalive_timeout 15s;
        send_timeout 10s;
        client_max_body_size 16m;

        location / {
            limit_req zone=req_limit_per_ip burst=20 nodelay;
            limit_conn conn_limit_per_ip 10;
            limit_req_status 429;
            proxy_pass http://backend_upstream;
        }

        location /api/login {
            limit_req zone=req_limit_per_ip burst=5 nodelay;
            limit_conn conn_limit_per_ip 3;
            proxy_pass http://backend_upstream;
        }
    }
}

Test the syntax and reload Nginx:

sudo nginx -t && sudo systemctl reload nginx

Active Socket Auditing and Fail2ban Integration

Monitor real-time active connections to detect uncharacteristically high socket usage from single subnets using ss:

ss -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head -n 10

Combine this visibility with Fail2ban. By tracking repeated HTTP 429 status codes in access logs, Fail2ban dynamically inserts temporary drop rules into the firewall, banishing offending bot IP addresses automatically.

Real-World Operational Scenarios and Use Cases

Mitigation strategies vary significantly across operational architectures. Implementing uniform defenses without analyzing application workloads risks service disruption or wasted resources.

1. High-Traffic eCommerce Platforms During Promotional Events

Online retailers face risks during high-traffic product launches when attackers deploy Layer 7 floods to crash databases or checkout endpoints. Blunt rate limits risk blocking paying customers.

Mitigation Approach: Deploy aggressive edge caching for product catalog pages, category listings, and static media files at the CDN edge with short TTLs. Isolate write-heavy endpoints (checkout and cart updates) behind dedicated API rate limiters with session cookie validation. Enforce Web Application Firewall rules that challenge clients with JavaScript execution proofs before allowing cart submissions.

2. Financial APIs and B2B SaaS Applications

Financial technology platforms and SaaS environments handle sensitive, automated machine-to-machine traffic. Unlike browser-driven websites, these endpoints process authenticated API calls where browser challenges break automated third-party client integrations.

Mitigation Approach: Enforce strict TLS mutual authentication (mTLS) or pre-shared API keys validated at the network edge. Restrict administrative endpoints and backend API controllers using IP allowlists. For public endpoints, deploy token-bucket rate limiters configured per API key rather than per IP address, preventing clients behind corporate NAT gateways from being throttled accidentally.

3. Multiplayer Gaming and Voice over IP (VoIP) Infrastructure

Real-time gaming and voice platforms rely on low-latency UDP communications. TCP-based proxy defenses do not apply to UDP datagram streams. Because UDP traffic is connectionless, source address spoofing is trivial for attackers.

Mitigation Approach: Deploy edge scrubbing filters that understand specific gaming protocol handshakes. Implement symmetric routing verification and challenge-response mechanisms that drop unauthenticated UDP packets before they reach game daemon processes. Operating systems must expand socket receive queues (net.core.rmem_max) to prevent packet drop during packet bursts.

Evaluating Architectural Trade-Offs: Cloud Scrubbing vs. On-Premises Appliances

Selecting a defense architecture involves balancing capacity, operational complexity, and infrastructure expenditure.

Architecture Type Mitigation Capacity Latency Impact Operational Complexity Primary Limitation
Cloud Anycast Scrubbing 50 Tbps+ (Global Scale) Low to moderate (routes through edge PoPs) Low (managed by provider) Ongoing subscription costs; SSL termination privacy considerations
On-Premises Hardware Appliances 10 Gbps – 100 Gbps Near zero (direct inline packet processing) High (requires network engineering staff) Cannot prevent upstream transit pipe saturation during large floods
Host-Level Kernel Hardening Limited by physical NIC (1–10 Gbps) Zero Moderate (manual configuration and testing) Fails when incoming bandwidth exceeds local uplink capacity

A hybrid model yields optimal resilience: combine an upstream Anycast scrubbing network to absorb volumetric floods with host-level sysctl tuning, XDP filtering, and Nginx rate limits to shield internal resources from Layer 7 attacks.

Common Operational Pitfalls During Attack Incidents

Awareness of common operational mistakes helps prevent self-inflicted outages during live attack events:

  • Leaking Origin IP Addresses: Deploying a reverse proxy or cloud protection service is useless if attackers discover your server’s true public IP address. Origin IPs frequently leak through outbound email headers (SMTP), misconfigured DNS records (such as unproxied mail or staging subdomains), or server status pages. Ensure direct access to origin IPs on ports 80 and 443 is blocked for all clients except your proxy provider’s IP blocks.
  • Relying Exclusively on Host Firewalls for Volumetric Floods: Attempting to block a 40 Gbps UDP flood using iptables on a 1 Gbps uplink will fail. The network interface becomes saturated before the kernel can read packet headers. Volumetric traffic must be mitigated upstream.
  • Overly Aggressive Rate Limiting Without Burst Buffering: Setting an Nginx rate limit of 5 requests per second without a burst buffer causes legitimate users to experience HTTP 429 errors simply by opening three browser tabs simultaneously. Always configure balanced burst allowances (e.g., burst=20 nodelay).
  • Ignoring Upstream Transit Alerts: Many hosting providers provide automated monitoring alerts when interface traffic approaches link saturation. Establishing automated escalation procedures ensures you can re-route traffic to scrubbing centers before carriers enforce blackholing.

Frequently Asked Questions

Why does enabling Linux SYN cookies degrade TCP options, and when should they be deployed?

When Linux activates SYN cookies (tcp_syncookies = 1), the kernel cannot store TCP options (such as selective acknowledgment SACK, large window scaling, and exact timestamp negotiations) because there is no allocated memory buffer for the half-open socket. Connection parameters must fit within the 32-bit sequence number. While modern Linux kernels use timestamp bits to encode a subset of these parameters, enabling SYN cookies slightly limits advanced TCP window performance. However, because the alternative during a flood is total service unavailability, keeping SYN cookies enabled serves as an essential defensive safety net.

What is the difference between BGP Anycast scrubbing and upstream Blackholing?

BGP Blackholing (null-routing) is an emergency defensive mechanism where upstream transit providers discard all traffic destined for a victim IP address to protect network infrastructure from congestion. This results in complete downtime for the targeted service. In contrast, BGP Anycast scrubbing directs traffic through globally distributed filtering centers that parse, inspect, and remove malicious packets while delivering clean packets to the origin server, maintaining uninterrupted uptime.

How do modern Layer 7 HTTP flood attacks bypass traditional Web Application Firewalls?

Modern Layer 7 attacks frequently rotate residential IP proxies, generate legitimate-looking User-Agent strings, and populate HTTP request headers with valid cookies. When attackers target non-cached search queries or computationally expensive dynamic endpoints (such as report generation or database searches), the request appears syntactically valid to traditional signature-based WAFs. Defeating these attacks requires behavioral rate limiting, TLS fingerprinting (JA3/JA4), and dynamic client execution challenges.

Why does conntrack table exhaustion crash a Linux server during a SYN flood before CPU reaches 100%?

The Linux Netfilter connection tracking subsystem (nf_conntrack) tracks the state of every connection in a finite memory table. When a high-rate SYN flood arrives, each spoofed half-open connection claims an entry in this table. Once the table reaches its limit (defined by net.netfilter.nf_conntrack_max), the kernel rejects all new incoming packets, triggering the error message nf_conntrack: table full, dropping packet. The server becomes completely unreachable even though CPU utilization and overall memory consumption remain low.

Can eBPF and XDP drop high-volume DDoS packets before they hit the Linux kernel network stack?

Yes. eXpress Data Path (XDP) runs custom eBPF bytecode directly inside the network interface driver layer at the earliest point of packet reception. When an incoming packet arrives, the XDP program inspects the raw packet header and can return an immediate XDP_DROP verdict. This happens before the Linux kernel allocates an sk_buff data structure, bypassing IP stack routing, Netfilter conntrack processing, and socket buffering. This allows modern servers to drop tens of millions of attack packets per second with minimal CPU overhead.

How should origin IP addresses be secured when using an edge reverse proxy?

To prevent attackers from bypassing your reverse proxy and attacking your origin server directly, configure local host firewalls (such as ufw or nftables) to drop all incoming traffic on web ports (80 and 443) unless the connection originates from the published IP subnets of your reverse proxy provider. All other direct connection attempts to the origin IP address must be rejected immediately at the firewall layer.