Secure VPS and only permit SSH access from your home network. Lookup Home IP and update the ufw SSH rule then send a ntfy notification.
The script could easily be adapted for other services like HTTP/HTTPS.
- Dynamic DNS client
- ufw
- ntfy
Use one of the free DDNS services or register a domain. Enable regular updates by running a DDNS Client from within your home network. This will provide IP updates to your Domain record when it changes.
I use the Cloudflare Registrar for Domains and pfsense's Dynamic DNS Service to keep the DNS record updated.
For notifications, use the paid or self hosted ntfy instance.
Download script to your home directory
wget https://github.com/hhanzo1/update-ufw-rule/blob/main/update-ufw-rule.sh
chmod +x update-ufw-rule.sh
Update the following variables:
DNS_HOSTNAME= NTFY_AUTH_TOKEN= NTFY_TOPIC=
Replace ntfy.sh with your self hosted ntfy URL.
If the ntfy CLI is not installed on the local host, update the ntfy notification functions to use curl instead.
#ntfy publish --token "$NTFY_AUTH_TOKEN" --tags="$NTFY_MESSAGE_FAILURE_TAG" "ntfy.sh/$NTFY_TOPIC" "$message"
curl -X POST \
-H "Authorization: Bearer $NTFY_AUTH_TOKEN" \
-H "Priority: high" \
-H "Tags: $NTFY_MESSAGE_FAILURE_TAG" \
-d "$message" \
https://ntfy.sh/DFqxU8kU2HYyX25N
Run the script manually to check it is working as expected, then scheduled via cron.
# Run every day
0 * * * * /home/[USERID]/update-ufw-rule.sh
There will be a ntfy push notification every time the update script is run.