Skip to content

Instantly share code, notes, and snippets.

@ecylmz
Created July 27, 2012 10:40
Show Gist options
  • Save ecylmz/3187380 to your computer and use it in GitHub Desktop.
Save ecylmz/3187380 to your computer and use it in GitHub Desktop.
Limit Connections Per Second
#!/bin/bash
# Source: http://www.cyberciti.biz/faq/iptables-connection-limits-howto/
IPT=/sbin/iptables
# Max connection in seconds
SECONDS=100
# Max connections per IP
BLOCKCOUNT=10
# ....
# ..
# default action can be DROP or REJECT
DACTION="DROP"
$IPT -A INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --set
$IPT -A INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --update --seconds ${SECONDS} --hitcount ${BLOCKCOUNT} -j ${DACTION}
# ....
# ..
#!/bin/bash
ip="202.1.2.3"
port="80"
for i in {1..100}
do
# do nothing just connect and exit
echo "exit" | nc ${ip} ${port};
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment