Created
October 22, 2024 20:12
-
-
Save yosignals/f025859ba9e6b41eef9d9e4200451801 to your computer and use it in GitHub Desktop.
not pretty
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 | |
# Filename: allow_uk_block_others.sh | |
# Step 1: Download UK IP ranges | |
echo "Downloading UK IP ranges..." | |
wget -q http://www.ipdeny.com/ipblocks/data/countries/gb.zone -O uk_ips.txt | |
# Check if the download was successful | |
if [ ! -f uk_ips.txt ]; then | |
echo "Failed to download UK IP ranges. Exiting." | |
exit 1 | |
fi | |
# Step 2: Allow only UK IP ranges | |
echo "Applying UFW rules for UK IP ranges..." | |
while read -r ip; do | |
sudo ufw allow from "$ip" | |
done < uk_ips.txt | |
# Step 3: Set default deny policies | |
echo "Setting default UFW policy to deny all other traffic..." | |
sudo ufw default deny incoming | |
sudo ufw default deny outgoing | |
# Step 4: Enable UFW | |
echo "Enabling UFW with new rules..." | |
sudo ufw enable | |
# Step 5: Verify the UFW rules | |
echo "Verifying UFW status..." | |
sudo ufw status | |
# Cleanup the downloaded IP list file | |
rm -f uk_ips.txt | |
echo "UFW configuration complete. Only UK traffic is allowed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment