Created
July 27, 2012 10:40
-
-
Save ecylmz/3187380 to your computer and use it in GitHub Desktop.
Limit Connections Per Second
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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} | |
# .... | |
# .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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