Dynamic DNS

Dynamic DNS, a method of keeping a domain name linked to a changing IP address as not all computers use static IP addresses. Typically, when a user connects to the Internet, the user's ISP assigns an unused IP address from a pool of IP addresses, and this address is used only for the duration of that specific connection. This method of dynamically assigning addresses extends the usable pool of available IP addresses.

A dynamic DNS service provider uses a special program that runs on the user's computer, contacting the DNS service each time the IP address provided by the ISP changes and subsequently updating the DNS database to reflect the change in IP address. In this way, even though a domain name's IP address will change often, other users do not have to know the changed IP address in order to connect with the other computer.

Notice: you can use IDN names.

Upcoming features

NONE

How-to setup Dynamic DNS

Use POST or GET method with the following url:

http[s]://system-ns.com/api?type=dynamic&domain=DOMAIN&command=COMMAND&token=TOKEN&ip=IP

  • Parameters:

    • type - dynamic
    • domain - your dynamic domain
    • token - your uniq token. You can receive it on Profile page.
    • ip (optional) - address that you wish to setup for domain
    • command - [set,get]
  • Command:

    • set - set new ip address for domain
    • get - return current ip address of domain
  • Return codes:

    • 0 - Success
    • 1 - Data invalid
    • 2 - Token invalid
    • 3 - Domain invalid
    • 4 - Auth invalid
    • 5 - Wrong ip format
    • 99- Another problem

Examples:


Windows example

Create a new file called system-ns.vbs in your home directory.
You should change domain and token parameters in the URL string.

Call SystemnsUpdate()

Sub SystemnsUpdate()
    On Error Resume Next
    Dim Request
    Dim URL

    URL = "https://system-ns.com/api?type=dynamic&domain=mydomain.system-ns.net&command=set&token=880078764367979fe765c0fa3f4efff1"

    Set Request = CreateObject("Microsoft.XMLHTTP")
    Request.open "GET", URL , false
    Request.Send

    Set Request = Nothing
End Sub

Now you can test this script by simply double click on it (you won't see any output) and check http[s]://system-ns.com/dynamic

So last thing to do is to schedule the job to run every 5 minutes.
For this you can use windows Task Scheduler.

OS X example

Open terminal.
Make directory and script file in it.

$ mkdir systemns
$ cd systemns
$ vi systemns.sh

Put this text in systemns.sh. You should change domain and token parameters.

#!/bin/bash
curl -s "https://system-ns.com/api?type=dynamic&domain=mydomain.system-ns.net&command=set&token=880078764367979fe765c0fa3f4efff1" | grep -v '"code":0' | awk '{print d, $0}' "d=$(date)" >> ~/systemns/systemns.log

Make the systemns.sh file executable.

$ chmod +x systemns.sh

Open crontab.

$ crontab -e

Put this text in the crontab (run every 5 minutes)

*/5 * * * * ~/systemns/systemns.sh

Linux example

Make directory and script file in it.

$ cd ~
$ mkdir systemns
$ cd systemns
$ vi systemns.sh

Put this text in systemns.sh. You should change domain and token parameters.

#!/bin/bash
wget -q -O- --post-data "type=dynamic&domain=mydomain.system-ns.net&command=set&token=880078764367979fe765c0fa3f4efff1" https://system-ns.com/api | grep -v '"code":0' | awk '{print d, $0}' "d=$(date)" >> ~/systemns/systemns.log

Make the systemns.sh file executable.

$ chmod +x systemns.sh

Open crontab.

$ crontab -e

Put this text in the crontab (run every 5 minutes)

*/5 * * * * ~/systemns/systemns.sh

EC2 Ubuntu example

Login to your EC2 instance over ssh.
Make directory and script file in it.

$ cd ~
$ mkdir systemns
$ cd systemns
$ vi systemns.sh

Put this text in systemns.sh. You should change domain and token parameters.

#!/bin/bash
current=""
while true; do
	latest=`ec2metadata --public-ipv4`
	echo "public-ipv4=$latest"
	if [ "$current" == "$latest" ]
	then
		echo "ip not changed"
	else
		echo "ip has changed - updating"
		current=$latest
		wget -q -O- --post-data "type=dynamic&domain=mydomain.system-ns.net&command=set&token=880078764367979fe765c0fa3f4efff1&ip=$current" https://system-ns.com/api | grep -v '"code":0' | awk '{print d, $0}' "d=$(date)" >> ~/systemns/systemns.log
	fi
	sleep 5m
done

Make the systemns.sh file executable.

$ chmod +x systemns.sh

Create the next script file

$ vi systemns_daemon.sh

Put this text in systemns_daemon.sh.

#!/bin/bash
nohup ~/systemns/systemns.sh 2>&1 &

Make the systemns_daemon.sh file executable.

$ chmod +x systemns_daemon.sh

Make the daemon auto start on boot.

$ sudo ln -s ~/systemns/systemns_daemon.sh /etc/rc2.d/S10systemns

OpenWRT example

Install the ddns-scripts package.

opkg update
opkg install ddns-scripts

Edit config file

/etc/config/ddns

You should change your token [option password] and domain [option domain] parameters

config service "systemns"
    option enabled "1"
    option interface "wan"

    option service_name "system-ns.com"
    option domain "mydomain.system-ns.net"
    option password "880078764367979fe765c0fa3f4efff1"

    option ip_source "network"
    option ip_network "wan"

    option force_interval "24"
    option force_unit "hours"
    option check_interval "5"
    option check_unit "minutes"

    option update_url "https://system-ns.com/api?type=dynamic&domain=[DOMAIN]&command=set&token=[PASSWORD]&ip=[IP]"

Now you should reboot your router or use

root@OpenWrt:~# ACTION=ifup INTERFACE=wan /sbin/hotplug-call iface

For more information about script options check http://wiki.openwrt.org/doc/howto/ddns.client