Skip to content

Instantly share code, notes, and snippets.

@lispstudent
Forked from bomale/ddns-update
Last active May 28, 2022 14:27
Show Gist options
  • Select an option

  • Save lispstudent/d248f4d96719a171dd1b6d067572eaf1 to your computer and use it in GitHub Desktop.

Select an option

Save lispstudent/d248f4d96719a171dd1b6d067572eaf1 to your computer and use it in GitHub Desktop.
Namecheap DDNS Updater Bash Script
#!/bin/sh
# make it executable `chmod +x ddns-update`
# move it path `mv ddns-update /usr/bin/`
# setup cronjob for every 15 minutes `crontab -e`
# */15 * * * * ddns-update >/dev/null 2>&1
# dont forget to change your own domain & password
# uncomment if you want internet connection check before running
#while ! ping -c 1 -W 1 8.8.8.8; do
# echo "DDNS-UPDATE: Waiting internet connection.."
# sleep 2
#done
last_ip_file="/tmp/last_ip"
last_ip=`cat $last_ip_file` # nslookup -type=A $domain | awk '/^Address: / { print $2 }'
echo "DDNS-UPDATE: OK, Getting public IP address"
ip=$(curl -s http://dynamicdns.park-your-domain.com/getip)
if [ "$ip" == "$last_ip" ]; then
echo "IP Still same, not need to update."
exit 0
fi
echo "DDNS-UPDATE: Public IP is: $ip, Updating IP..."
host="vm.domain.tld"
# or host="@" for bare domain
domain="your-own-domain.tld"
password="your-own-password"
response=$(curl -s "https://dynamicdns.park-your-domain.com/update?host=$host&domain=$domain&password=$password&ip=$ip")
if echo $response | grep -q "<ErrCount>0</ErrCount>"; then
echo "Server DNS record updated ($last_ip -> $ip)"
echo $ip > $last_ip_file
else
echo "Server DNS record update FAILED (tried $last_ip -> $ip)"
echo $response
fi
@lispstudent

lispstudent commented May 20, 2022

Copy link
Copy Markdown
Author

This works as of FreeBSD 13.1-RELEASE. Many thanks to @ndunks for the original script.

@ndunks

ndunks commented May 28, 2022

Copy link
Copy Markdown

thanks for your comment..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment