-
-
Save mskian/2afa263f0de9c0be72e0cc55ca92a6b9 to your computer and use it in GitHub Desktop.
Pi-hole - A Simple Bash Script to Update the Home/ISP ip address in UFW Firewall to access port 53
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
VPSIP=XXX.XX.XX.X | |
PASSWORD='SERVERPASSWORD' |
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 | |
# Setup Reference: https://blog.sbstp.ca/vps-pihole/ | |
# Load ENV Variables | |
. .env | |
# GET IP | |
ip=$(curl -s https://api.ipify.org) | |
# File Name | |
ip_file="ip_data.txt" | |
# Load VPS IP from ENV | |
vps_ip=$VPSIP | |
# Verify File exist or not | |
if [ -f "$ip_file" ]; then | |
source $ip_file | |
echo "Get IP from data file: $data" | |
else | |
echo "$ip_file does not exist." | |
exit 1 | |
fi | |
# Updating Firewall Rules | |
if [ $ip = $data ]; then | |
echo "IP Exist in UFW Rules - Readded for Verification" | |
sleep 2; | |
sshpass -p $PASSWORD ssh root@$vps_ip "ufw allow from $ip to any port 53 && ufw reload" | |
else | |
sshpass -p $PASSWORD ssh root@$vps_ip "ufw delete allow from $data to any port 53 && ufw reload" | |
sleep 2; | |
sshpass -p $PASSWORD ssh root@$vps_ip "ufw allow from $ip to any port 53 && ufw reload" | |
sleep 2; | |
echo "data=$ip" > $ip_file | |
fi |
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 | |
# Setup Reference: https://blog.sbstp.ca/vps-pihole/ | |
ip=$(curl -s https://api.ipify.org) | |
ip_file="ip_data.txt" | |
echo "data=$ip" > $ip_file | |
echo "Your Network IP is $ip" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment