Powerful anti-ddos shell script

Source: Internet
Author: User

Author: Gao Jinbo

The server has been under DDOS attacks for the past few days. Currently, only IP address sources can be blocked for the time being. It is a nightmare to manually add IP addresses without changing the source. I thought of a way to use SHELL.

Relatively simple, but very practical :) the following content should be modified according to the author's original article :)

1. write scripts
 

Mkdir/root/bin vi/root/bin/dropip. sh #! /Bin/bash/bin/netstat-nagrep ESTABLISHEDawk '{print $5}' awk-F: '{print $1}' sortuniq-csort-rnhead-10 grep-v-E '192. 168127.0 'awk' {if ($2! = Null & $1> 4) {print $2} '>/tmp/dropip for I in $ (cat/tmp/dropip) do/sbin/iptables-a input-s $ I-j DROP echo "$ I kill at 'date'">/var/log/ddos done 2. add execution permission
Chmod + x/root/bin/dropip. sh

3. Added to the scheduled task and executed every minute
Crontab-e
*/1 */root/bin/dropip. sh

Note:
The above script is relatively simple, but very practical. The most important thing is that in the second line, get the first 10 ip addresses with the maximum number of ESTABLISHED connections and write them to the temporary file/tmp/dropip, the internal ip segment starting with 192.168127.0 is excluded. use the for loop to drop all the ip addresses in the dropip through iptables, and then write them to the log file/var/log/ddos.

 

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.