This script will update the A
DNS record for a domain/subdomain at NearlyFreeSpeech.NET
with the public IP address for the machine the script runs on. Run this script on a server in which the public IP
address is dynamic and changes so your domain is always up to date.
There are two steps to this script. First, it retrieves the configured IP address for the domain/subdomain, the current public
IP address of the server, and then compares the two. If the public IP address is different, it updates the A
record of
the domain/subdomain with the new IP address.
Tcl, Tcllib, and TclTLS are the only requirements. They come pre-installed or are easily installed on most *nix operating systems.
Configurations are set by providing the script with environment variables
Env Variable | Required | Description |
---|---|---|
USERNAME | Y | Your NFSN username |
API_KEY | Y | API key for using NFSN's APIs. This can be obtained via the Member Interface > "Profile" tab > "Actions" > "Manage API Key" |
DOMAIN | Y | Domain that the subdomain belongs to |
SUBDOMAIN | N | Subdomain to update with the script. Leave blank for the bare domain name |
IP_PROVIDER | N | Use a different IP providing service than the default: http://ipinfo.io/ip This might be useful if the default provider is unavailable or is blocked. The alternate provider MUST be served over http (please open an issue if this is ever a problem) and MUST return ONLY the IP in the response body |
It is as easy as running: tclsh dns.tcl
or make it executable with chmod u+x dns.tcl
and then run ./dns.tcl
To include all of the environmental variables inline when running, you can do something like this:
$ export USERNAME=username API_KEY=api_key DOMAIN=domain.com SUBDOMAIN=subdomain && ./dns.tcl
-
Set the configuration values in the script the way you want them (or create a file containing the environment variables)
-
Build the image with
docker build -t nfs-dynamic-dns .
-
Run the image (production) with
docker run -d --name nfsn-dynamic-dns nfs-dynamic-dns
(add the--env-file <file>
argument before the lastnfsn-dynamic-dns
if you want to use your environment variable file)Ex:
docker run -d --name nfsn-dynamic-dns --env-file .env nfs-dynamic-dns
You can use the following config to run this with docker compose.
version: "3"
services:
nfs-dynamic-dns:
image: nfs-dynamic-dns
build: ./nfs-dynamic-dns
container_name: nfs-dynamic-dns
network_mode: host
environment:
- USERNAME=username
- API_KEY=api_key
- DOMAIN=domain.com
- SUBDOMAIN=subdomain
restart: unless-stopped
To run the container locally (and let it run its cronjobs), use this command:
docker run -it --rm --init nfs-dynamic-dns
to run the container locally and be put into a shell where you can run ./dns.tcl
yourself use this:
docker run -it --rm --init nfs-dynamic-dns sh
If your setup uses environment variables, you will also need to add the --env-file
argument (or specify variables individually with the -e
docker flag). The --env-file
option is for docker run and the env file format can be found here.
It can be setup to run as a cron job to completely automate this process. Something such as:
@hourly /usr/local/bin/tclsh /scripts/nfs-dynamic-dns/dns.tcl
When using the Docker file, it's by default scheduled to run every 30 minutes. However, this is configurable when building the
container. The CRON_SCHEDULE
build arg can be overriden.
With docker, the build step (step 2) can be done like this:
$ docker build --build-arg CRON_SCHEDULE="*/5 * * * *" -t nfs-dynamic-dns .
With docker compose, it can be done like this:
version: "3"
services:
nfs-dynamic-dns:
image: nfs-dynamic-dns
build:
context: ./nfs-dynamic-dns
args:
- CRON_SCHEDULE=*/5 * * * *
container_name: nfs-dynamic-dns
...
The script communicates with NearlyFreeSpeech.NET via its RESTful API. Specifics about the API can be found here.