DoS & DDoS Mitigation

Denial-of-Service attacks overwhelm your server with requests until it becomes unreachable. This guide covers what protective measures you can implement directly on your server.

On This Page

DoS vs. DDoS: A simple DoS attack originates from a single source and can be effectively mitigated on the server itself. A distributed DDoS attack involving thousands of source IPs exceeds the capacity of a single server — here, an upstream DDoS protection service is the only effective solution.

Protection Measures at a Glance

Comprehensive DoS protection consists of multiple layers. The table below shows which measures work at which level:

MeasureLayerProtects against
iptables / nftables Rate LimitNetworkSYN floods, connection floods
Fail2BanApplicationBrute-force, SSH attacks, HTTP scans
Nginx / Apache Rate LimitingHTTPSlowloris, HTTP floods, API abuse
Harden / relocate SSHServiceSSH brute-force, automated scans
External DDoS protectionUpstreamVolumetric DDoS attacks

Recommended Values by Server Type

The right rate limit values depend heavily on your server's purpose. The table below provides orientation values — adjust them to match your actual traffic levels:

Server TypeSSHHTTP/HTTPSNotes
Web Server / WordPress3/min, burst 520/s, burst 100Nginx rate limiting additionally recommended
Game Server3/min, burst 5Protect game ports (e.g. UDP 25565) separately; use more generous burst values for legitimate players
Mail Server3/min, burst 5Protect SMTP (25), IMAP (993), POP3 (995) separately with Fail2Ban — brute-force on mail accounts is common

Tip: Start with slightly generous values and monitor your logs — limits that are too strict can block legitimate users.

1. Rate Limiting with iptables

Using the limit and recent modules, you can cap the number of new connections per IP and time window.

Protect SSH (port 22)

Allow a maximum of 3 new connections per minute — further attempts are dropped for 1 minute once the limit is reached:

Terminal
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m limit --limit 3/m --limit-burst 5 -j ACCEPT iptables -A INPUT -p tcp --dport 22 -j DROP

Protect Web Server (ports 80 / 443)

Limits established connections to 20 per second per IP — protects against Slowloris and HTTP floods. Adjust the value to match your normal traffic level:

Terminal
iptables -A INPUT -p tcp --dport 80 -m state --state ESTABLISHED -m limit --limit 20/s --limit-burst 100 -j ACCEPT iptables -A INPUT -p tcp --dport 80 -j DROP iptables -A INPUT -p tcp --dport 443 -m state --state ESTABLISHED -m limit --limit 20/s --limit-burst 100 -j ACCEPT iptables -A INPUT -p tcp --dport 443 -j DROP

Temporary IP blocking with the recent module

IPs sending more than 15 new packets within 60 seconds are automatically blocked:

Terminal
iptables -A INPUT -p tcp --dport 80 -m state --state NEW -m recent --set iptables -A INPUT -p tcp --dport 80 -m state --state NEW -m recent --update --seconds 60 --hitcount 15 -j DROP iptables -A INPUT -p tcp --dport 80 -j ACCEPT

2. Rate Limiting with nftables

nftables allows rate limiting to be defined directly in the configuration file — more readable and more performant than iptables:

SSH brute-force protection

Allow a maximum of 5 new SSH connections per minute per IP — further attempts are dropped:

Terminal
tcp dport 22 ct state new limit rate 5/minute accept tcp dport 22 ct state new drop

HTTP flood protection

Limits new HTTP connections to 100 per second — excess requests are dropped:

Terminal
tcp dport { 80, 443 } ct state new limit rate 100/second accept tcp dport { 80, 443 } ct state new drop

SYN flood protection

Drops TCP packets without a valid connection state — significantly reduces SYN flood attacks:

Terminal
tcp flags syn / fin,syn,rst,ack limit rate 1000/second burst 2000 packets accept tcp flags syn / fin,syn,rst,ack drop

Add rate limiting rules directly inside the input chain of your /etc/nftables.conf — before the final DROP policy. Reload the configuration with nft -f /etc/nftables.conf.

3. Fail2Ban — Automatic IP Blocking

Fail2Ban monitors log files and automatically bans IPs that produce too many failed attempts. It works seamlessly with both iptables and nftables.

Installation

Terminal
apt update && apt install fail2ban

Enable SSH protection

Create a local configuration file that bans SSH addresses for 1 hour after 5 failed attempts:

/etc/fail2ban/jail.local
[sshd] enabled = true port = ssh maxretry = 5 bantime = 3600 findtime = 600

Start service & check status

Terminal
systemctl enable --now fail2ban fail2ban-client status sshd

4. Nginx Rate Limiting

Nginx offers built-in rate limiting at the HTTP layer — ideal against Slowloris, API abuse, and HTTP floods that have already passed the firewall.

Define a rate limit zone

Add the following line to the http block of your Nginx configuration:

nginx.conf — http block
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;

Apply the rate limit to a server block

nginx.conf — server block
server { location / { limit_req zone=one burst=20 nodelay; } }

rate=10r/s allows 10 requests per second per IP. burst=20 permits short spikes up to 20 requests — excess requests beyond that are rejected with HTTP 503.

5. Rate Limiting on Windows

On Windows servers, Windows Defender Firewall combined with PowerShell handles protection. Full connection rate limiting is more limited on Windows than Linux, but essential protective measures are available.

Restrict RDP Access (Port 3389)

RDP is the most common attack target on Windows servers. Restrict access to known IP addresses only:

PowerShell
New-NetFirewallRule -DisplayName "RDP restricted" -Direction Inbound -LocalPort 3389 -Protocol TCP -Action Allow -RemoteAddress 192.0.2.5 New-NetFirewallRule -DisplayName "RDP block all" -Direction Inbound -LocalPort 3389 -Protocol TCP -Action Block

Recommended Values for Windows Servers

Server TypeRDPRecommendation
Web Server (IIS)Admin IP onlyEnable IIS Dynamic IP Restrictions module
Game ServerAdmin IP onlyExplicitly allow game ports, block everything else
Mail ServerAdmin IP onlyOnly open SMTP/IMAP/POP3 ports for necessary sources

Enable Account Lockout Policy

Configure account lockout in Local Security Policy (secpol.msc) after too many failed attempts — acts like Fail2Ban for RDP and local logins:

SettingRecommended Value
Account lockout threshold5 failed attempts
Account lockout duration30 minutes
Observation window15 minutes

6. Save Rules Persistently

iptables rules are lost after a reboot. Save them persistently:

Debian / Ubuntu

Terminal
apt install iptables-persistent netfilter-persistent save

CentOS / RHEL

Terminal
iptables-save > /etc/sysconfig/iptables systemctl restart iptables

nftables (all distributions)

Terminal
nft list ruleset > /etc/nftables.conf systemctl enable --now nftables

7. External DDoS Protection

For volumetric DDoS attacks (multiple Gbit/s), server-side measures are ineffective — the upstream link is already saturated before packets reach the server. In this case, an upstream protection service is required:

CDN with DDoS Protection
Many CDN providers offer built-in DDoS protection — activated simply by changing your DNS records.
Server4You Network Protection
As your hosting provider, we have network-level protection in place. Volumetric attacks are detected and mitigated at the infrastructure level before they ever reach your server.
Dedicated Scrubbing
Specialized DDoS protection services for enterprises with high-availability requirements.

Full Firewall Guides

For complete firewall configurations with a default-deny strategy, see our detailed guides.