Skip to content

Instantly share code, notes, and snippets.

@dalhundal
Created May 4, 2014 16:48
Show Gist options
  • Save dalhundal/89159b3f032588586e91 to your computer and use it in GitHub Desktop.
Save dalhundal/89159b3f032588586e91 to your computer and use it in GitHub Desktop.
Shell script to update namecheap.com dynamic dns for a domain with your external IP address
#!/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"
@nikmartin
Copy link

Line 10needs to be updated to:

IP=`curl -s ipecho.net/plain`

As echoip.com no longer exists

@jack3898
Copy link

7 years old and very helpful. Thanks!

@shreyansp
Copy link

shreyansp commented Aug 18, 2021

Not sure if this is new feature of namecheap dynamic DNS, but if you're just going to set it to the IP you're calling the URL from, then no need to specify the IP, it is determined automatically.
(reduces the dependency in another 3rd party service)

IP Address = optional value. If you don't specify any IP, the IP from which you are accessing this URL will be set for the domain

https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-do-i-use-a-browser-to-dynamically-update-the-hosts-ip/

Just use:

curl "https://dynamicdns.park-your-domain.com/update?host=$HOSTNAME&domain=$DOMAIN&password=$PASSWORD"

@dbudzins
Copy link

Awesome, worked like a charm on my tomato router. Thanks all!

@That-Dude
Copy link

Minor change to only update the dynamic DNS record when required. Allows for frequent update checking without hammering the namecheap update API.

#!/bin/sh

# Shell script to update namecheap.com dynamic dns as required
# for a domain to your external IP address

HOSTNAME=yoursubdomain
DOMAIN=yourdomainname.com
PASSWORD=y0urp455w0rd

CURRENT_IP=$(curl ifconfig.io)
DYN_IP=$( host "$HOSTNAME.$DOMAIN" | sed -e "s/.*\ //" )

if [ "$DYN_IP" != "$CURRENT_IP" ]; then
    curl "https://dynamicdns.park-your-domain.com/update?host=$HOSTNAME&domain=$DOMAIN&password=$PASSWORD"
fi

@mslinn
Copy link

mslinn commented Jun 29, 2022

This works fine if HOSTNAME has a value, like 'www'. That would update the DNS for www.yourdomain.com.

I tried setting HOSTNAME to '@' to update the base domain (yourdomain.com) but got an error. Then I tried setting it to '', also no good. How to set the DNS value of @?

@That-Dude
Copy link

That-Dude commented Jun 30, 2022

Does this work? (I can't test it right now)

host=@
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")
echo $response

@mslinn
Copy link

mslinn commented Jun 30, 2022 via email

@That-Dude
Copy link

That-Dude commented Jun 30, 2022

Here's namecheap's own documentation, unless I'm missing something we're updating using the described method:

https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-to-dynamically-update-the-hosts-ip-with-an-http-request/

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.

@mslinn
Copy link

mslinn commented Jun 30, 2022 via email

@That-Dude
Copy link

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.

@mslinn
Copy link

mslinn commented Jun 30, 2022 via email

@itiligent
Copy link

itiligent commented Dec 10, 2023

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

@alexspurling
Copy link

What the heck is park-your-domain.com and why would I send them my namecheap credentials? Is this a scam?

@dalhundal
Copy link
Author

dalhundal commented Jan 14, 2024 via email

@alexspurling
Copy link

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?

@dalhundal
Copy link
Author

dalhundal commented Jan 14, 2024 via email

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