Linode Dynamic DNS (DDNS) Update Script

If you have a web server running on your linode and another location on a Dynamic DNS, and would like to update linode’s DNS without logging in via ssh, here’s my implementation.

——————————-

This is a PHP script that runs on your web server and returns the IP address of the client. Create it in the web root on your web server and save as MyIP.php

<?php
echo $_SERVER['REMOTE_ADDR'];
?>

——————————-

This is a shell script that runs on the remote (dynamic) machine. Name it anything you like and put it /etc/cron.hourly.

Change the variables to reflect your settings.

Note that it only updates the DNS when your WAN IP has actually changed.

You can pick up this entire document without any formatting problems at:

http://www.cnysupport.com/index.php/linode-dynamic-dns-ddns-update-script

#!/bin/sh
LINODE_API_KEY=your linode key
DOMAIN_ID=your domain id
RESOURCE_ID=your resource id
WAN_IP=`wget -O - -q http://www.sampledomain.com/MyIP.php`
OLD_WAN_IP=`cat /var/CURRENT_WAN_IP.txt`
if [ "$WAN_IP" = "$OLD_WAN_IP" ]; then
echo "IP Unchanged"
else
echo $WAN_IP > /var/CURRENT_WAN_IP.txt
wget -qO- https://api.linode.com/?api_key="$LINODE_API_KEY"\&api_action=domain.resource.update\&DomainID="$DOMAIN_ID"\&ResourceID="$RESOURCE_ID"\&Target="$WAN_IP"
fi

————————-

Enjoy!

Terry

One Response to Linode Dynamic DNS (DDNS) Update Script

  1. Pingback: Blog about nothing - Ditching DynDNS