[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