Skip to content

Lookup Home IP, update the ufw SSH rule then send a ntfy notification

License

Notifications You must be signed in to change notification settings

hhanzo1/update-ufw-rule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

About

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.

Getting Started

Prerequisites

  • Dynamic DNS client
  • ufw
  • ntfy

Dynamic DNS

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.

ntfy

For notifications, use the paid or self hosted ntfy instance.

Installation

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

Usage

Run the script manually to check it is working as expected, then scheduled via cron.

Enable the update script

# Run every day
0 * * * * /home/[USERID]/update-ufw-rule.sh

There will be a ntfy push notification every time the update script is run.

Acknowledgments