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 canyouseeme.org 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:
* danfolkes.com : that keeps it’s IP. It has PHP.
* lab.danfolkes.com : that changes it’s IP.
I setup a cron job on lab.danfolkes.com to run every 8 hours and open a PHP page:
0 */8 * * * /usr/bin/curl "http://danfolkes.com/path/to/file.php"
The page on danfolkes.com will record the last 50 IPs sent to it in a logfile:
// danfolkes.com/path/to/file.php: $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 lab.danfolkes.com and set them to the new IP.
<!-- Log File --> <br/>2013-07-30 12:56:09 184.108.40.206 <br/>2013-07-30 04:56:10 220.127.116.11 <br/>2013-07-29 20:56:21 18.104.22.168 <br/>2013-07-29 20:56:19 22.214.171.124 <br/>2013-07-29 20:56:15 126.96.36.199 <br/>2013-07-29 20:56:12 188.8.131.52 <br/>2013-07-29 20:55:48 184.108.40.206 <br/>2013-07-29 20:55:32 220.127.116.11 <br/>2013-07-29 20:50:04 18.104.22.168