If you are looking for a way to quickly and easily block an IP from connecting to your server using the IPtables firewall then just use this script.
First off you need to make yourself root. Then you type in:
vi /usr/local/bin/blockip
Then just paste in this code:
#!/bin/sh
if [ "$1" != "" ]; then
/sbin/iptables -I INPUT -s $1 -j DROP
else
echo “Type an IP”
echo “Usage:”
echo ” Blockip <ipaddress>”
echo “”
fi
After you get that done you need to make the file executable, so just run this command:
chmod u+x /usr/local/bin/blockip
Now all you need to do to block an ip is type in the command like this (remember to change the IP to the one that you want to block) :
blcokip 20.2.2.20
That’s all there is to it! If you encounter any problems with this script please let me know, but I tested it and it should work.