Anti-DDoS attack shell script

Source: Internet
Author: User

Recently, the server has been frequently attacked by DDoS, so it can only be solved temporarily by IP source. IP is not the source of changeable, light by hand to add is simply a nightmare, think of a method, with the shell to do.

Relatively simple, but very useful:) The following content according to the author's original text to make appropriate changes:)

1. Scripting

mkdir/root/binvi/root/bin/dropip.sh #!/bin/bash/bin/netstat-nagrep established awk ' {print} ' awk-f: ' {print} ' Sortuni Q-csort-rnhead-10grep-v-E ' 192.168 127.0′awk ' {if (!=null && >4) {print}} ' >/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. Increase execution Privileges

chmod +x/root/bin/dropip.sh

3. Add to Scheduled Tasks, execute once per minute

Crontab-e

*/1 * * * */root/bin/dropip.sh

Description

The above script is relatively simple, but very practical, the most important is the second row, get the top 10 established connections and write to the temporary file/tmp/dropip, excluding the internal IP segment 192.168- 127.0 starts with a for loop, the IP inside the DROPIP is dropped by Iptables and then written to the log file/var/log/ddos

Anti-DDoS attack shell script

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.