Get a Server’s IP that is Always Changing

So, my server at home’s IP address is always changing. Sometimes it’s sitting there broadcasting my development server’s website to the world on an IP that I don’t know.

So, when this happens, I have to go get physical access and bring up or something like it.

There are a few solutions to this problem:

  • DynDNS – A good solution, but I hate that they will cancel your service when you don’t login.
  • Get a static IP from your ISP – Costs extra money
  • Somehow, get the server to broadcast it’s address to a static place

I went with the last option. You could do this in a multitude of ways. You could have your server send it’s address in an email to you periodically or on boot. You could FTP it to a free FTP server. You get the idea.

I did this:
* : that keeps it’s IP. It has PHP.
* : that changes it’s IP.

I setup a cron job on to run every 8 hours and open a PHP page:

0 */8 * * * /usr/bin/curl ""

The page on will record the last 50 IPs sent to it in a logfile:

	$file = 'log/file.txt';
	$max = 50;
	$content = "\n<br/>" . date("Y-m-d H:i:s") . " " . $_SERVER['REMOTE_ADDR'] . "";
	$filecontents = file_get_contents($file);
	$filecontents = $content . $filecontents;
	$filecontents = implode("\n<br/>", array_slice(explode("\n<br/>", $filecontents),0, $max));
	echo $filecontents;
	file_put_contents($file, $filecontents);

So, if my server’s IP ever changes, there will be a nice little record of the last known IPs. I can go into my DNS settings for and set them to the new IP.

<!-- Log File -->
<br/>2013-07-30 12:56:09
<br/>2013-07-30 04:56:10
<br/>2013-07-29 20:56:21
<br/>2013-07-29 20:56:19
<br/>2013-07-29 20:56:15
<br/>2013-07-29 20:56:12
<br/>2013-07-29 20:55:48
<br/>2013-07-29 20:55:32
<br/>2013-07-29 20:50:04