Free DNS offers free dynamic and static DNS hosting. You can visit their website or read more about some uses of their service here.
If you are hosting your website from a server that has a dynamic IP address you might wonder how you can map your domain name (specifically TLD) directly to your server. Sure you can use CNAME records to point your subdomains to another DNS service like no-ip but where is fun in that? Also that doesn’t help your TLD (top-level domain) which needs to be set via an A Record.
Be warned: you should not use a CNAME record with a TLD, it may cause issues with other services on the domain, like email.
FreeDNS provides an API to update your A Record as your dynamic IP address changes. They provide several scripts that work in conjunction with a unique “Authentication Token” that allow this to be possible. These scripts are written for windows, linux, and even certain routers! I think these scripts are only available once you have a login (it’s free)!
I wanted to better understand the process and create something light-weight so I wrote my own tcl script to use:
#!/usr/local/bin/tclsh8.6# updateIp.tcl# This is a simple script that will detect the server's external IP address # (as seen by the outside world) and update your domain's A Record via FreeDNS# (freedns.afraid.org). Of course this implies that you have changed your# domain to use freedns's nameservers and have your domain configured there# (it's free!) # This script should be run as part of a cron job every ~5 minutes# Usage:# Check for updates and apply as necessary:# ./updateIp.tcl# Force an update# ./updateIp.tcl true#-----BEGIN USER GLOBALS SECTION-----## File in which to write logs (should use syslog to rotate)set g_logFile "/var/log/updateIp.log"# File that stores the current IP of the server # (will be maintained by this script)set g_currentIp "/usr/local/www/updateIp/currentIp.conf"# Authentication token that is generated and obtained from FreeDNS for# your spefic domain# YOU MUST UPDATE THESE WITH YOUR OWN DOMAINS TOKENS!set g_authToken [list U2lSMUlBQUoz_______x2 U2lSMUta2Vz_________x3]#------END USER GLOBALS SECTION------##------YOU SHOULDN'T NEED TO CHANGE ANYTHING BEYOND THIS POINT-------#package require http
# Logs "msg" along with a timestamp to g_logFileproc logger {msg}\{global g_logFile
set fp [open$g_logFile"WRONLY APPEND CREAT"]puts$fp"[clock format [clock scan now]]: $msg"}# Retrieves the external IP address of this server (using dyndns)proc getExternalIp {}\{set token [::http::geturl http://checkip.dyndns.org]set data [::http::data $token]regexp{Address:(\d+\.\d+\.\d+\.\d+)}$data-> ipAddress
return$ipAddress}# Retrieves the current external IP address that this server is aware of# (using the g_currentIp file)proc getCurrentIp {}\{global g_currentIp
set fp [open$g_currentIp"RDWR CREAT"]set ip [lindex[split[read$fp]"\n"]0]close$fpreturn$ip}# Updates FreeDNS to your new external IP. Also updates g_currentIp so we# know when we need to update again proc updateIp {ip}\{global g_currentIp
global g_authToken
foreach part $g_authToken\{set token [::http::geturl http://freedns.afraid.org/dynamic/update.php?$part]logger[::http::data $token]}set fp [open$g_currentIp"WRONLY CREAT TRUNC"]puts$fp$ipclose$fp}# Main program# Get the current known IP of the system (stored in g_currentIp)set currentIP [getCurrentIp]# Get the current external IP of the system (from dyndns)set externIP [getExternalIp]set force [lindex$argv0]if{$forceeq""}\{set force false
}# If our IP has changed (or if we are forcing) then update it!if{($currentIPne$externIP)||$force}\{logger"updating IP ($externIP) - force: $force"updateIp$externIP}\else\{logger"IP Address is up-to-date"}
Now you simply need to call ./updateIp.tcl in a cron job and your domain will stay updated with your ever changing IP address!
Eventually I will add this to github in case anyone would like to use or improve upon it.