Created
February 20, 2021 00:59
-
-
Save InfamousStarFox/919949e6638b1bbd9b3b393658f145b8 to your computer and use it in GitHub Desktop.
Ubiquiti EdgeRouter NameSilo Dynamic DNS
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 | |
# For Ubiquiti EdgeOS | |
# This script will set the NameSilo ip address to the router's external ip address | |
# Place the file in /etc/cron.hourly | |
# Domain name: | |
DOMAIN="mydomain.tld"; | |
# Host name (subdomain). Optional. If present, must end with a dot (.) | |
HOST="subdomain."; | |
# APIKEY obtained from Namesilo: | |
APIKEY="12345"; | |
#----- Stop Editing -----# | |
# Saved history pubic IP from last check | |
IP_FILE="/var/tmp/MyPubIP"; | |
# Get the current public IP | |
CUR_IP="$(show interfaces ethernet | grep "^eth0" | grep -oP '([0-9]{1,3}\.){3}[0-9]{1,3}')"; | |
# Check file for previous IP address | |
if [ -f $IP_FILE ]; then | |
KNOWN_IP=$(cat $IP_FILE); | |
else | |
KNOWN_IP=''; | |
fi | |
# See if the IP has changed | |
if [ "$CUR_IP" != "$KNOWN_IP" ]; then | |
echo $CUR_IP > $IP_FILE; | |
# Get DNS record id from Namesilo: | |
curl -s "https://www.namesilo.com/api/dnsListRecords?version=1&type=xml&key=$APIKEY&domain=$DOMAIN" > $DOMAIN.xml | |
RECORD_ID=`xmllint --xpath "//namesilo/reply/resource_record/record_id[../host/text() = '$HOST$DOMAIN' ]" $DOMAIN.xml | grep -oP '(?<=<record_id>).*?(?=</record_id>)'` | |
# Set DNS record in Namesilo: | |
curl -s "https://www.namesilo.com/api/dnsUpdateRecord?version=1&type=xml&key=$APIKEY&domain=$DOMAIN&rrid=$RECORD_ID&rrhost=$HOST&rrvalue=$CUR_IP&rrttl=3600" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment