Automatically intercept DDoS attacks with shell scripts

Source: Internet
Author: User

#!/bin/bash 
#fix by Leipore at 2014-12-18ddos-autoprotection.sh
Touch/root/back_bad_ip.txt 
Time= ' date + '%y-%m-%d%h:%m:%s ' 
Ar= ' wc-l/root/back_bad_ip.txt |awk ' {print $} ' 
Sleep 1 
Netstat-an |grep |grep-v "STREAM" |awk ' {print $} ' |sort | Awk-f: ' {print $} ' |uniq-c |awk ' $ > $ {print $1,$2} ' >/root/bad_ip; 
Cat/root/bad_ip |awk-vtime= "$time" ' {Print time ' | "$" | ">>/root/back_bad_ip.txt}" 
Ar2= ' wc-l/root/back_bad_ip.txt |awk ' {print $} ' 
For i in ' awk ' {print $ {} '/root/bad_ip ';d o 
If [' $i ' = ' ""];then 
Exit:q
Else 
Iptables-i input-s $i-j DROP 
Fi 
Done 
sum=$[$ar 2-$ar] 
If ["$sum"-eq 0];then 
Exit 
Else 
/usr/lib/sendmail-f [Email protected] [email protected] -S Smtp.xx.cn-u "Subject:report"-xu [email protected]-XP xxxxxx-m </root/back_bad_ip.txt 
Fi



#!/bin/bash

While [1]

Do

sh/scripts/ddos-autoprotection.sh

Sleep 30

Done

Nohup sh/scripts/ddos-check.sh & (boot start)



650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>


Disadvantages:

    • Repeat iptables Disabled.

    • Do not write iptables daily, that is to say, restart failure

    • Need to restart iptables (optional)

    • The link between the agent and the agent below this limit will also be limited such as the LO Nic local network card, etc.



Automatically intercept DDoS attacks with shell scripts

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.