Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Tips/Tricks/Mods

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 21st May 2009, 20: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

Code:
<!--#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.

Code:
<?php

// Configuration
$db_server = 'localhost';
$db_user = 'root';
$db_password = 'password';
$echo_page = 'http://remote.example.com/ip.shtml';   
$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'");
}
else
{
 echo ' ... No Change.';
}
mysql_close($con);

?>
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?
__________________
System6Hosting.com, ISPConfig 3, Debian.
Reply With Quote
The Following User Says Thank You to BorderAmigos For This Useful Post:
falko (22nd May 2009)
Sponsored Links
  #2  
Old 10th July 2009, 17:51
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

I did some updates to this little script. Sometimes my remote server wasn't responding and so I would have an empty IP address. I added a check do do nothing if this is the case.

Also added some lines to email me when the IP changed, one of which goes to my cell phone. This script runs on a cron job every 10 minutes with the output piped to a log file. The log file is rotated with logrotated. Seems to work well so far.

Putting the update here just in case anyone can use it.

Quote:
<?php
// Configuration
$db_server = 'localhost';
$db_user = 'root';
$db_password = 'password';
$echo_page = 'http://remoteserver.com/ip/index.shtml'; // <!--#echo var="REMOTE_ADDR" -->
// Find current dynamic IP address
$echoed_ip = trim(file_get_contents($echo_page));
echo date('l jS F Y h:i:s A');
if (!$echoed_ip == '')
{
// Find current stored IP address
$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;
}
}
if ($change_flag)
{
$ipmessage=' - IP Changed from '.$stored_ip.' to '.$echoed_ip.'.';
echo $ipmessage;
mysql_query("UPDATE dns_rr SET data='$echoed_ip' WHERE type='A'");
mail('me@yahoo.com','IP Change',$ipmessage);
mail('0005551212@vtext.com','IP Change',$ipmessage);
}
else
{
echo ' ... No Change.';
}
mysql_close($con);
}
else
{
echo '!!! Null IP !!!';
}
?>
__________________
System6Hosting.com, ISPConfig 3, Debian.
Reply With Quote
The Following User Says Thank You to BorderAmigos For This Useful Post:
falko (11th July 2009)
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The system is currently updating the configuration files. warlock General 8 21st February 2009 18:15
Squid Proxy Caching on Linux obzerver Installation/Configuration 4 13th August 2008 19:51
Google Apps dayjahone General 19 29th March 2008 17:25
DNS Configuration Problems VMartins Installation/Configuration 10 24th July 2007 14:40
HotSaNIC domino Tips/Tricks/Mods 23 6th November 2006 05:19


All times are GMT +2. The time now is 18:47.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.