Serving pages over a dynamic ip can be frustrating, especially if you try to use a free dynamic dns account. Many of them expire if not used in X number of days, some cost more many than your actual domain and a lot of the built in clients in many of today’s popular routers don’t work reliably.
This is where some custom script foo comes in. Using industry standards like SSH, SSI’s and cronjobs we can setup a super lightweight script that sends your dynamic ip to a webserver so that it can direct visitors to your in house server.
The graphic below should help visualize:
As you can see from the diagram this script runs, gathers a single variable and then pushes it out to a server via ssh. From there the server calls that file and uses the ip as a variable to pass along to clients visiting the website by using a simple meta refresh.
Dynamic IP Configuration
After getting ssh keys setup there are really only 2 steps to getting this script to work. If you haven’t set those up before refer to this guide for help.
Step 1. Download the ip_updater.sh script here and change the following 4 variables to your own setup
IDENTITY = path to your ssh identity file (usually ~/.ssh/identity or ~/.ssh/id_rsa)
DEST_SERVER = ip or hostname of the server you’re sending your ip to
DEST_FILE = temp file on the server that holds your ip (/tmp/myip)
USERNAME = username to logon as
Step 2. Setup a crontab to run this script at certain intervals
Here is my sample crontab which runs this script once an hour at 15 after:
# m h dom mon dow command 15 * * * * /home/alt229/bin/ip_update.sh
Web Server Configuration
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Zync Catalog Redirect</title> <meta http-equiv="refresh" content="0;URL='http://<!--#include virtual="cableip" -->'" /> </head> <body bgcolor="#000000"> <p>Redirecting you to <!--#include virtual="myip" --></p> </body> </html>
When clients hit your server and get served this page they will automatically get redirected to your dynamic address.