Use iptables to automatically block IP addresses with a large number of connections to prevent CC attacks

Source: Internet
Author: User

This method is used to passively count the number of IP connections. iptables is used to block IP addresses with a large number of connections. For more information, see iptables to limit the number of ip connections to prevent CC attacks.
The Shell script is as follows:
 
#! /Bin/bash
# Created by http://www.bkjia.com
Num = 100 # Upper Limit
List = 'netstat-an | grep ^ tcp. *: 80 | egrep-v 'Listen | 127.0.0.1 '| awk-F "[] + | [:] "'{print $6}' | sort | uniq-c | sort-rn | awk '{if ($1> $ num) {print $2 }}''
For I in $ list
Do
Iptables-I input-s $ I -- dport 80-j DROP
Done
 
Join crontab to schedule tasks
 
Crontab-e
*/5 * sh/path/file. sh # Run the command once every 5 minutes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.