- sign up for a dreamhost API Key with "All DNS" permissions at https://panel.dreamhost.com/index.cgi?tree=home.api
- copy config.sh to /etc/dreamhost/config.sh and fill out the variables
- copy ddns.sh to /usr/local/dreamhost/ddns.sh
- copy dreamhost_cron to /etc/cron.d/dreamhost_cron
Last active
May 1, 2019 00:22
-
-
Save caleblloyd/43f468e547ada577bb6aa705bc1c82ff to your computer and use it in GitHub Desktop.
Dreamhost API Dynamic DNS cron script
This file contains 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/sh | |
# file location: /etc/dreamhost/config.sh | |
KEY="AAA1112223334444" # dreamhost api key | |
DDNS_SUBDOMAIN="subdomain.example.com" # dynamic dns subdomain | |
DDNS_INTERFACE="eth0" # interface to use IPV4 from | |
DDNS_LAST_IP_FILE="/var/lib/dreamhost/last_ip.txt" # file to store most recent IPV4 in |
This file contains 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/sh | |
# file location /usr/local/dreamhost/ddns.sh | |
source /etc/dreamhost/config.sh | |
last_ip="" | |
if [ -f $DDNS_LAST_IP_FILE ] | |
then | |
last_ip=$( cat $DDNS_LAST_IP_FILE | head -n 1 | awk '{ print $1}' ) | |
fi | |
ip=$( ifconfig $DDNS_INTERFACE | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' ) | |
if [ "$ip" != "$last_ip" ] | |
then | |
echo "Updating IP Address to $ip" | |
dh_last_ip=$(curl -s -H "Content-Type: application/x-www-form-urlencoded" -X POST -d \ | |
"key=$KEY&cmd=dns-list_records" \ | |
https://api.dreamhost.com/ \ | |
| grep $DDNS_SUBDOMAIN | cut -d: -f2 | awk '{print $5}') | |
curl -s -H "Content-Type: application/x-www-form-urlencoded" -X POST -d \ | |
"key=$KEY&cmd=dns-remove_record&record=$DDNS_SUBDOMAIN&type=A&value=$dh_last_ip" \ | |
https://api.dreamhost.com/ | |
curl -s -H "Content-Type: application/x-www-form-urlencoded" -X POST -d \ | |
"key=$KEY&cmd=dns-add_record&record=$DDNS_SUBDOMAIN&type=A&value=$ip" \ | |
https://api.dreamhost.com/ | |
mkdir -p $( dirname $DDNS_LAST_IP_FILE ) | |
echo "$ip" > $DDNS_LAST_IP_FILE | |
fi |
This file contains 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
# file location /etc/cron.d/dreamhost_cron | |
SHELL=/bin/sh | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
* * * * * root /bin/bash /usr/local/dreamhost/ddns.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment