Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!

#!/bin/bash
PATH=/sbin:/usr/sbin:$PATH
date=`date +"%Y%m%d%H%M"`
iptables -t raw -L PREROUTING -vnxZ | perl -ne 'split/ +/;print "$_[8]\n" if $_[1] ne "0";' | xargs -I {} iptables -t raw -D PREROUTING -s {} -j DROP
log_dir=/var/lib/vservers/perfccc/var/www/logs/typofront/
cd ${log_dir}
pid=`cat /var/lib/vservers/perfccc/var/run/nginx.pid`
mv ${log_dir}/typofront.access.log ${log_dir}/typofront.access.${date}.log
/usr/sbin/vkill -s USR1 ${pid}
grep "GET /experts/extrasensy/index.html HTTP" ${log_dir}/typofront.access.${date}.log | cut -d ' ' -f 1 | sort | uniq -dc | sort -nr | perl -ne 'split /\s+/; print "$_[2]\n" if ($_[1]>30);' | xargs -I {} iptables -t raw -I PREROUTING -s {} -j DROP
/bin/gzip ${log_dir}/typofront.access.${date}.log
-Z, --zero [chain [rulenum]]
Zero the packet and byte counters in all chains, or only the given chain, or only the given rule in a chain. It is
legal to specify the -L, --list (list) option as well, to see the counters immediately before they are cleared. (See
above.)
-x, --exact
Expand numbers. Display the exact value of the packet and byte counters, instead of only the rounded number in K's
(multiples of 1000) M's (multiples of 1000K) or G's (multiples of 1000M). This option is only relevant for the -L
command.
# !! Don't forget to add restart of log2ban.py on log rotation !!
#
ECHO_LOG_COMMAND = "tail -f /var/log/nginx/access.log" # shell command
Практический эпизод борьбы с DDoS