Created
December 22, 2016 17:55
-
-
Save briantissue/c80a1d823ae88cd0077b22dbfbd5442b to your computer and use it in GitHub Desktop.
This script allows you to quickly block source IP addresses, say during an attempted attack with Ubuntu's UFW
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 | |
# Check if root | |
if [ "$(whoami)" != "root" ]; then | |
echo "Not running as root. Exiting..." | |
exit 0 | |
else | |
echo "Editing and Reviewing UFW Firewall Entries" | |
fi | |
sudo ufw status numbered | |
read -p 'Please review the above rules-The IP entry you add in the next step will add it to the top of the hierarchy....' | |
read -p "IP Address to Block/CIDR: " IP_ADDRESS | |
echo "*****************************" | |
echo "Source IP Address to Block:" $IP_ADDRESS | |
echo "*****************************" | |
echo "Is the information listed above correct? [Y,n]" | |
read input | |
if [[ $input == "Y" || $input == "y" ]]; then | |
sudo ufw insert 1 deny from $IP_ADDRESS to any | |
else | |
sudo ufw status numbered | |
echo "No Changes Made" | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment