Last active
November 1, 2023 17:27
-
-
Save ramit-mitra/f72b16b34099f85b3423bd32f63930c3 to your computer and use it in GitHub Desktop.
Block banned IPs using UFW
This file contains hidden or 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 | |
# Example: curl -sk https://gist.githubusercontent.com/ramit-mitra/f72b16b34099f85b3423bd32f63930c3/raw/ufw_block_banned_ips.sh | bash | |
url="https://raw.githubusercontent.com/ramit-mitra/blocklist-ipsets/main/rottenIPs.json" | |
echo "-------------------------" | |
echo "Reading Banlist IPs..." | |
blocked_ips=$(curl -s $url | jq -r '.[]') | |
echo "Banning IPs (using UFW)..." | |
echo "-------------------------" | |
for ip in $blocked_ips; do | |
echo $ip | |
sudo ufw deny from $ip to any > /dev/null | |
done | |
echo "-------------------------" | |
sudo ufw reload | |
sudo ufw status | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment