Below is a script that I use to notify via e-mail and update my WireGuard enabled devices of any IP changes. FTR I used an AI agent to build. If you have better ideas, would be interested in hearing.
================================================================================
IPFIRE: EMAIL NOTIFICATION ON WAN IP CHANGE
STEP 1: CONFIGURING THE IPFIRE MAIL SERVICE
- Log into your IPFire Web User Interface (WUI).
- Navigate to System > Mail Service.
- Configure your upstream SMTP server details, username, password, and recipient.
- Click Save, then click “Send test mail” to verify it works.
STEP 2: DEPLOYING THE MONITORING SCRIPT
-
Log into IPFire via SSH as root and create the tracking directory:
mkdir -p /var/tmp/mail -
Create and open the script file using nano:
EDITOR=nano nano /var/tmp/mail/check_wan_ip.sh -
Paste the following script into the file (be sure to replace the placeholder
emails at the bottom with your actual addresses):
#!/bin/bash
Detect current RED interface IP
CURRENT_IP=$(/sbin/ip address show dev red0 | /bin/grep inet | /usr/bin/awk ‘{print $2}’ | /usr/bin/cut -d’/’ -f1)
if [ -z “$CURRENT_IP” ]; then
CURRENT_IP=$(/usr/bin/curl -s https://ifconfig.me)
fi
Tracking file must reside in a globally accessible directory
IP_FILE=“/var/tmp/mail/ip_red_alt”
if [ ! -f “$IP_FILE” ]; then
echo “$CURRENT_IP” > “$IP_FILE”
chmod 666 “$IP_FILE”
exit 0
fi
OLD_IP=$(cat “$IP_FILE”)
if [ “$CURRENT_IP” != “$OLD_IP” ] && [ ! -z “$CURRENT_IP” ]; then
echo “$CURRENT_IP” > “$IP_FILE”
# !!! CONFIGURATION SECTION !!!
TO="your-recipient-email@domain.com"
FROM="your-configured-email@domain.com"
(
echo "Subject: IPFire Alert: WAN IP Changed"
echo "From: $FROM"
echo "To: $TO"
echo ""
echo "The IPFire RED WAN IP address has changed."
echo "Old IP: $OLD_IP"
echo "New IP: $CURRENT_IP"
echo "Timestamp: $(date)"
) | /usr/sbin/sendmail -t -f "$FROM"
fi
- Save and exit (Ctrl+O, Enter, then Ctrl+X).
- Make the script executable:
chmod 755 /var/tmp/mail/check_wan_ip.sh
STEP 3: CONFIGURING THE CRON JOB AUTOMATION
-
Open the crontab configuration using nano:
EDITOR=nano fcrontab -e -
Scroll to the very bottom line and add the 5-minute interval trigger:
*/5 * * * * /var/tmp/mail/check_wan_ip.sh -
Save and exit (Ctrl+O, Enter, then Ctrl+X).
-
Verify the cron job is active by running:
fcrontab -l
STEP 4: TESTING THE BACKEND PIPELINE
Run these commands to simulate an IP change and force an alert: