View Single Post
Old 21st May 2009, 21:42
BorderAmigos BorderAmigos is offline
Senior Member
Join Date: Apr 2008
Location: San Diego & Tijuana
Posts: 302
Thanks: 26
Thanked 33 Times in 31 Posts
Send a message via MSN to BorderAmigos Send a message via Yahoo to BorderAmigos
Default Update for dynamic dns...

Here's my thoughts for updating my ISPConfig3 MyDNS when my dynamic IP changes. I haven't had it change yet so I'm not 100% sure it's going to work.

On a remote server that has server side includes there is ip.shtml that contains only this line

<!--#echo var="REMOTE_ADDR" -->
When accessed this will give the current actual IP to my local server. The remote server is outside my local router.

Then there is a cron job running update_ip_address.php every 10 minutes. This file outputs to dynamic.html which is just an indication if something changed or not.


// Configuration
$db_server = 'localhost';
$db_user = 'root';
$db_password = 'password';
$echo_page = '';   
$echoed_ip = trim(file_get_contents($echo_page));

$con = mysql_connect($db_server,$db_user,$db_password);
if (!$con) die('Could not connect: ' . mysql_error());

mysql_select_db('dbispconfig', $con);
$table_data = mysql_query("SELECT * FROM dns_rr");

$change_flag = false;
while ($item_data = mysql_fetch_array($table_data))
 if ($item_data['type'] == 'A')
  $stored_ip = trim($item_data['data']);
  if (!($stored_ip == $echoed_ip)) $change_flag = true;
echo date('l jS F Y h:i:s A');
if ($change_flag)
 echo ' ... IP Changed from '.$stored_ip.' to '.$echoed_ip.'.';
 mysql_query("UPDATE dns_rr SET data='$echoed_ip' WHERE type='A'");
 echo ' ... No Change.';

Basically, it gets the current IP echoed from the remote host, compares it to all the A records in the database that ISPConfig3 MyDNS is using, then UPDATEs them if they are different.

I haven't had my IP address change yet but this seems like it should work. Thoughts? Comments?
__________________, ISPConfig 3, Debian.
Reply With Quote
Sponsored Links