iptables is a firewall software that operates on the Linux operating system, and it is compatible with various Linux distributions, such as CentOS and Ubuntu. This article explains how to use iptables to block a large number of concurrent connections within a short period. The methods described can also be utilized to defend against some basic forms of DDoS attacks.
Most Linux operating systems come with iptables pre-installed. Use the following command to verify if iptables is installed:
which iptables
If it returns a path similar to /sbin/iptables, it indicates that iptables has been successfully installed. If no path is returned, use the following commands to install:
For CentOS:
yum install iptables
For Debian/Ubuntu:
apt-get install iptables iptables-persistent
Monitor incoming connections on the eth0 interface and port 80:
iptables -I INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --set
If there are more than 10 new incoming connections within 60 seconds, drop them:
iptables -I INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 10 -j DROP
After creating iptables rules, it is necessary to save and load iptables to ensure that the rules are permanently effective.
service iptables-persistent save
service iptables-persistent reload
This concludes the method for using iptables on a Linux cloud server environment to block a high number of concurrent connections in a short time.
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58