Call firewall to block DDoS initiator IP

Source: Internet
Author: User
Tags ip number

[email protected] ~]# cat fw.sh
#!/bin/bash
Cat/var/log/nginx/access.log|awk-f ":" ' {print $} ' |sort|uniq-c|sort-rn|head-10|grep-v "127.0" |awk ' {if ($2!=null &A mp;& $1>4) {print $}} ' >/tmp/dropip
For I in $ (CAT/TMP/DROPIP)
Do
/sbin/iptables-a input-p TCP--dport 80-s $i-j DROP
echo "$i kill at Date" >>/var/log/ddos
Done


Script Annotations:

First look at the log file, awk filter out the first column of IP, and sort, go to heavy, then reverse sort, filter out the top 10 IP, exclude 127.0 IP, and then filter out the second column is not empty and IP number is greater than 4 IP, and print IP output to the/tmp/dropip file.

Looping Files/tmp/dropip

80 port that/tmp/dropip the IP address inside the

Write this event into the/var/log/ddos log and cycle again.


This article is from the "Linux" blog, so be sure to keep this source http://chenjisong.blog.51cto.com/7858025/1789244

Call firewall to block DDoS initiator IP

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.