Skip to content

Instantly share code, notes, and snippets.

@fahadysf
Created October 14, 2022 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahadysf/835982f015a7b6264b9acff7c8583e50 to your computer and use it in GitHub Desktop.
Save fahadysf/835982f015a7b6264b9acff7c8583e50 to your computer and use it in GitHub Desktop.
Bash script to update NameCheap DDNS
#!/bin/sh
dnsserver="freedns2.registrar-servers.com"
host="host"
domain_name="your.domain"
ddns_password="YOUR-DDNS-PASSWORD-HERE"
dnsrecord=$host.$domain_name
# Get the current external IP address
current_ip=`curl -s -X GET https://checkip.amazonaws.com`
datestr=`date`
## NameChaep FreeDNS Dynamic Update URL
## keep these private
UPDATE_URL="https://dynamicdns.park-your-domain.com/update?host=$host&domain=$domain_name&password=$ddns_password&ip=$current_ip"
echo "[$datestr] Current IP is $current_ip"
dnsresult="[$datestr] `host $dnsrecord $dnsserver | grep 'has address'`"
if echo $dnsresult | grep "$current_ip"; then
echo "[$datestr] $dnsrecord is currently set to $current_ip; no changes needed"
exit 0
fi
# if here, the dns record needs updating
result=`curl -s -X GET $UPDATE_URL`
echo "[$datestr] Update Result: \n$result"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment