rendered paste body#!/bin/bash
shortseconds=1
shorthits=10
longseconds=60
/sbin/service iptables restart
#/sbin/iptables -F
/sbin/iptables -N phyin
/sbin/iptables -N block
/sbin/iptables -N ratelimit
/sbin/iptables -N rateshort
/sbin/iptables -N ratelong
#/sbin/iptables -A FORWARD -m physdev --physdev-in eth0 -j phyin
/sbin/iptables -A INPUT -j phyin
/sbin/iptables -A phyin -j block
/sbin/iptables -A phyin -j ratelimit
for net in 0.0.0.0/5 8.0.0.0/5 16.0.0.0/5 24.0.0.0/5 32.0.0.0/5 40.0.0.0/5 48.0.0.0/5 48.0.0.0/5 56.0.0.0/5 64.0.0.0/5 72.0.0.0/5 80.0.0.0/5 88.0.0.0/5 96.0.0.0/5 104.0.0.0/5 112.0.0.0/5 120.0.0.0/5 128.0.0.0/5 136.0.0.0/5 144.0.0.0/5 15
2.0.0.0/5 160.0.0.0/5 168.0.0.0/5 176.0.0.0/5 184.0.0.0/5 192.0.0.0/5 200.0.0.0/5 208.0.0.0/5 216.0.0.0/5
do
bucket=`echo $net | cut -d. -f1`
/sbin/iptables -A ratelimit -p tcp -s $net --dport 80 --syn -m recent --update --seconds $longseconds --hitcount 1 -j DROP --name long.$bucket
/sbin/iptables -A ratelimit -p tcp -s $net --dport 80 --syn -m recent --rcheck --name short.$bucket -j rateshort
/sbin/iptables -A ratelimit -p tcp -s $net --dport 80 --syn -m recent --set --name short.$bucket
/sbin/iptables -A rateshort -p tcp -s $net --dport 80 --syn -m recent --update --seconds $shortseconds --hitcount $shorthits -j ratelong --name short.$bucket
/sbin/iptables -A ratelong -p tcp -s $net --dport 80 --syn -m recent --set --name long.$bucket
done
/sbin/iptables -A ratelong -j DROP