A straightforward bash script to automatically update your dynamic IP address with OpenDNS.
# Quick OpenDNS IP updater
user="home@example.com"
pass="secretpass"
host_label="home-internet"
# grab current public IP
cur_ip=$(curl -s https://api.ipify.org)
# files for storing previous IP and logs
prev_ip_file="$HOME/.opendns_last_ip"
logfile="$HOME/opendns_log.txt"
# read last known IP if exists
if [ -f "$prev_ip_file" ]; then
prev_ip=$(cat "$prev_ip_file")
else
prev_ip=""
fi
# if IP changed, tell OpenDNS
if [ "$cur_ip" != "$prev_ip" ]; then
echo "$(date): Whoa! IP changed from $prev_ip to $cur_ip. Sending update..." >> "$logfile"
curl -u "$user:$pass" "https://updates.opendns.com/nic/update?hostname=$host_label&myip=$cur_ip"
echo "$cur_ip" > "$prev_ip_file"
else
echo "$(date): IP stayed the same, nothing to do." >> "$logfile"
fi
git clone https://github.com/hexpad/opendns-updater.git
cd opendns-updater
chmod +x opendns_updater.sh
nano opendns_updater.sh
After editing the lines below, save and exit:
USERNAME="your-email@example.com"
PASSWORD="your-password"
LABEL="home-internet"
Use the open . command to access the log file location.
Sun Apr 20 11:59:01 +03 2025: IP changed: 140.171.118.36 → 226.196.65.78
The script can be run automatically with cron
Check your current terminal path:
pwd
Add cronjob
echo '* * * * * /bin/bash /your/path/opendns_updater.sh' | crontab -