-
-
Save madkoding/059974047e481e863f46df6bd05ae82b 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 every certain minutes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Shell script to update Namecheap.com dynamic DNS | |
# for a domain to your external IP address | |
# Configuration - replace these with your details or read from a secure location | |
HOSTNAME=yoursubdomain | |
DOMAIN=yourdomainname.com | |
PASSWORD=y0urp455w0rd | |
# Check if curl is installed | |
if ! command -v curl &> /dev/null; then | |
echo "curl could not be found, please install it first." | |
exit 1 | |
fi | |
# Fetch the current external IP address | |
IP=$(curl -s ipecho.net/plain) | |
if [ -z "$IP" ]; then | |
echo "Failed to obtain external IP address." | |
exit 1 | |
fi | |
# Update DNS record | |
UPDATE_URL="https://dynamicdns.park-your-domain.com/update?host=$HOSTNAME&domain=$DOMAIN&password=$PASSWORD&ip=$IP" | |
RESPONSE=$(curl -s "$UPDATE_URL") | |
# Log response | |
echo "Update response: $RESPONSE" | |
# Check if the update was successful | |
if echo "$RESPONSE" | grep -q "200 Success"; then | |
echo "DNS update successful." | |
else | |
echo "DNS update failed." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment