Quick Script to Block an IP Address
If you want to quickly block an IP address from connecting to your server using the iptables firewall, just use the following shell script.
Create a new script (as root) somewhere available in the path by using this command:
Now paste in the following code:
#!/bin/sh if [ "$1" != "" ]; then /sbin/iptables -I INPUT -s $1 -j DROP else echo "Dude, like, Type an IP or something." echo "Usage:" echo " blockip <ipaddress>" echo "" fi
Once you are done, you need to make it executable by running the following command:
chmod u+x /usr/local/bin/blockip
Now you can use the script like this:
That's all there really is to it.