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"
@tollopa
Copy link

tollopa commented Aug 24, 2024

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

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