A DDoS attack (Distributed Denial of Service) aims to overwhelm a network with excessive traffic, reducing its performance or causing a complete outage. This is reflected in the term "denial-of-service" (refusal of service).
The frequency and intensity of DDoS attacks have been rising rapidly. A report by Cloudflare noted that in 2021, the number of attacks grew by one-third compared to 2020, with a peak in activity observed in December.
The duration of a DDoS attack can vary. According to research by Securelist:
If you don't want to rely on vendors' solutions, paid services, or proprietary software, you can use the following tools to defend against DDoS attacks:
The IPTables tool helps protect a server from basic DDoS attacks. Its primary function is to filter incoming traffic through special tables. The resource owner can add custom tables.
Each table contains a set of rules that govern the tool's behavior in specific situations. By default, there are only two response options: ACCEPT
(allow access) and REJECT
(block access).
In IPTables, it is possible to limit the number of connections. If a single IP address exceeds the allowed number of connections, the tool will block access for that IP. You can extend the tool's functionality with additional criteria:
Additionally, IPTables can use criteria such as Owner, State, TOS, TTL, and Unclean Match to set personalized configurations, effectively protecting the resource from DDoS attacks.
The ipset
kernel module allows you to create a list of addresses that exceed the specified connection limit. The ipset timeout
parameter sets a time limit for the created list, which is enough to ride out a DDoS attack.
By default, IPTables settings return to their basic configuration after a system reboot. To save the settings, you can use additional utilities (such as
iptables-save
oriptables-persistent
), but it is recommended to start with the default options to avoid saving incorrect settings that could block server access for everyone.
While IPTables is a convenient and effective tool, it can be quite complex to configure. You’ll need to learn how to manage it and write additional scripts, and if something goes wrong, your resource may end up being a "closed club" for just a few users.
CSF (ConfigServer Security and Firewall) is a "turnkey" configurator, meaning you only need to set the correct parameters and not worry about the server's security.
The preliminary installation steps involve downloading two additional components required to run CSF: the Perl interpreter and the libwww
library. The next step is to install ConfigServer Security and Firewall itself. Since the tool is not available in the official repository, you'll need to download it directly from the provided link or by fetching the ready-made archive:
cd /usr/src
wget https://download.configserver.com/csf.tgz
After downloading, extract the archive and move it to the defender’s files folder. Then, run the installation process. Once installed successfully, you can proceed with configuring CSF.
By default, the settings in ConfigServer and Firewall are active for 5 minutes, after which any changes are reset. This test format is useful for conducting experiments and understanding errors in the applied configuration. To switch to live mode, change the Testing
value to 0.
Proper configuration of CSF ensures reliable protection against DDoS attacks. Here are some essential commands in CSF:
Specify incoming ports:
TCP_IN = "22,23,25,36,75,87"
Specify outgoing ports:
TCP_OUT = "22,23,25,36,75,87"
Configure email notifications for SSH connections:
LF_SSH_EMAIL_ALERT = "1"
Add an IP address to the exception list (useful for server management teams):
csf -a 192.168.0.7
Block a specific IP address from connecting to the server:
csf -d 192.168.0.6
How can you protect your server from DDoS attacks using simpler methods? Use Nginx modules like limit_conn
and limit_req
. The limit_conn
module limits the maximum number of connections to the server, while the limit_req
module limits the number of requests within a specified time frame.
For example, if you want to limit the number of simultaneous connections to 30 and restrict the number of connections within a 3-second window, the configuration will look as follows:
limit_conn_zone $binary_remote_addr zone=perip: 30m;
limit_req_zone $binary_remote_addr zone=dynamic:30m rate=3r/s;
This configuration allows only 3 requests per second. Any additional requests are queued. The burst parameter controls the queue size. For example, if the burst value is set to 7, the module will queue up to 7 requests when the request count exceeds 10, while any further requests will be rejected with an error.
Server protection against DDoS attacks can also be achieved using web applications. A traffic filter uses JavaScript, which is inaccessible to bots, effectively redirecting DDoS attacks to a placeholder page.
The operation of the filter is simple. The configuration defines conditions for blocking bots, and when a visitor meets those conditions, they are redirected to a placeholder page instead of the requested page. The filter can also specify the reason for the redirection.