Skip to content

Instantly share code, notes, and snippets.

@mcnaveen
Last active May 21, 2023 11:36
Show Gist options
  • Save mcnaveen/806a7e5d66fae9d5aad7e89b6b27346c to your computer and use it in GitHub Desktop.
Save mcnaveen/806a7e5d66fae9d5aad7e89b6b27346c to your computer and use it in GitHub Desktop.
Periodically check home IP address and update on server to allow port 53
#!/bin/bash
# Setup Reference: https://blog.sbstp.ca/vps-pihole/
# Run this script as CRON Job in your laptop or any device.
# Author - mcnaveen<[email protected]>
ip=$(curl -s https://api.ipify.org | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
ip_file="ip_address.txt"
vps_ip="YOUR_VPS_IP_ADDRESS"
if [[ -f $ip_file ]]; then
stored_ip=$(cat $ip_file)
fi
if [[ $ip != $stored_ip ]]; then
ssh root@$vps_ip "sudo ufw delete allow from $stored_ip to any port 53 && sudo ufw allow from $ip to any port 53"
fi
echo $ip > $ip_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment