-
-
Save dalhundal/89159b3f032588586e91 to your computer and use it in GitHub Desktop.
#!/bin/sh | |
# Shell script to update namecheap.com dynamic dns | |
# for a domain to your external IP address | |
HOSTNAME=yoursubdomain | |
DOMAIN=yourdomainname.com | |
PASSWORD=y0urp455w0rd | |
IP=`curl -s echoip.com` | |
curl "https://dynamicdns.park-your-domain.com/update?host=$HOSTNAME&domain=$DOMAIN&password=$PASSWORD&ip=$IP" |
mslinn
commented
Jun 30, 2022
via email
•
Here's namecheap's own documentation, unless I'm missing something we're updating using the described method:
One thing to double check, on your namecheap DNS you do have the @ record host type set to "A+ Dynamic DNS record" ?
If that's correct then I'd open a support case with namecheap.
According to this you should be using the "A+ Dynamic DNS record". Whilst it might work now with a regular "A record" there's a chance that functionality will be deprecated in the future YMMV.
Here's something that brings together several of the ideas above.
- Prevents clobbering the Namecheap update servers
- Only relies on core internet services from OpenDNS/dnsOmatic infrastructure (robust and purpose buit for ddns use cases)
- Will also discover AWS public DHCP IP addresses properly if you have a lot of internal RFC1918 DNS going on.
#!/bin/sh
# Shell script to update Namecheap.com dynamic dns
DDNS_HOSTNAME=hostname
DDNS_DOMAIN=example.com
DDNS_PASSWORD=XXXXXXXXXXX
CURRENT_IP=$(curl myip.dnsomatic.com)
CURRENT_DDNS=$(dig +short $DDNS_HOSTNAME.$DDNS_DOMAIN @resolver1.opendns.com)
echo "current Namecheap ddns record = $CURRENT_DDNS"
echo "current AWS public IP address = $CURRENT_IP"
if [ "$CURRENT_DDNS" != "$CURRENT_IP" ]; then
curl "https://dynamicdns.park-your-domain.com/update?
host=$DDNS_HOSTNAME&domain=$DDNS_DOMAIN&password=$DDNS_PASSWORD&ip=$CURRENT_IP"
fi
What the heck is park-your-domain.com and why would I send them my namecheap credentials? Is this a scam?
Thanks - I did search and didn't find any mention of park-your-domain.com in Namecheap's documentation. Why don't they use namecheap.com or api.namecheap.com as their API domain?
I made a couple of changes:
- Permits using "@" where you only have the TLD
- "silenced" the first curl
- Displays the Host and Domain values
- Changed the "dig"s to query dns1.registrar-servers.com since those are currently what NameCheap updates
#!/bin/bash
# Bash script to update Namecheap.com dynamic dns
DDNS_HOSTNAME="@"
DDNS_DOMAIN="YourDomainHere.com"
DDNS_PASSWORD="01234567890123456789012345678901"
CURRENT_IP=$(curl -s myip.dnsomatic.com)
if [[ "$DDNS_HOSTNAME" == "@" ]]; then
CURRENT_DDNS=$(dig +short $DDNS_DOMAIN @dns1.registrar-servers.com)
else
CURRENT_DDNS=$(dig +short $DDNS_HOSTNAME.$DDNS_DOMAIN @dns1.registrar-servers.com)
fi
echo "Hostname: $DDNS_HOSTNAME; Domain: $DDNS_DOMAIN"
echo "current Namecheap ddns record = $CURRENT_DDNS"
echo "current public IP address = $CURRENT_IP"
if [ "$CURRENT_DDNS" != "$CURRENT_IP" ]; then
curl "https://dynamicdns.park-your-domain.com/update?host=$DDNS_HOSTNAME&domain=$DDNS_DOMAIN&password=$DDNS_PASSWORD&ip=$CURRENT_IP"
fi