Duck DNS is a free dynamic DNS hosted on AWS, that we can use to get a free domain name. There a lot of free Dynamic DNS services, you can find a good comprehensive of them here as well as No-IP that we already have a guide, but Duck DNS is dead simple and has instructions for how to configure on every possible platform or system.

The only negative for this service is the limited subdomains that we can choose from. Because we can only choose a *.duckdns.org subdomain, if for example hobbit.duckdns.org is not available we will have to choose a different subdomain. This is not true for all dynamic DNS services, as we could keep the hobbit subdomain and change the host name to some other free one.

In this post, we will see how we can set up Duck DNS on a linux machine in order to point a subdomain (subdomain.duckdns.org) to our dynamic IP provided by the ISP or even to a static IP for our VPS that we have from a service like Digital Ocean, AWS, Linode, etc.

For Dynamic IP

The following instructions are mostly for using Duck DNS for a system in our home, where we don’t have a static IP address from our ISP, and we want to bind our public dynamic IP to a free domain.

Prerequisites

  1. Sign in with your preferred method at the Duck DNS website in order to add a new domain and create a token for your account. For our guide we will pick the mordor.duckdns.org domain.

  2. Make sure your linux install is running a crontab. You can check it with this command:

ps -ef | grep cr[o]n
  1. Make sure you have curl installed. You can check it with this command:
curl

Create duckdns script

Create a directory to put your files in, move into it and make the main script:

mkdir duckdns
cd duckdns
vim duck.sh

Now copy the following text into the file and change your DOMAIN, TOKEN to be the one you want to update and save the file:

#!/bin/sh

DOMAIN="mordor"
TOKEN="a7c4d0ad-114e-40ef-ba1d-d217904a50f2"

curl -k -o ~/duckdns/duck.log "https://www.duckdns.org/update?domains=${DOMAIN}&token=${TOKEN}"

You can hard code an IP, but is best to leave it blank and let duckdns detect it).

This script will make a https request and log the output in the file duck.log.

Make the file executable:

chmod 700 duck.sh

Test script

If we run the script:

./duck.sh

and open the log file:

cat duck.log

we should see an OK response. If we see an KO response something is wrong and you should check that the Token and Domain are correct in the duck.sh script.

Create a cron process

We will be using the cron process to make the script get run every 5 minutes. Open crontab:

crontab -e

and paste the following text at the end of the file:

*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1

This will run the script every 5 minutes and ignore the output.

For Static IP

The following simple instructions are mostly for using Duck DNS as a DNS registrar, in order to bind our static IP address that we have from some provider for our server to a free domain.

Prerequisites

  1. Sign in with your preferred method at the Duck DNS website in order to add a new domain and create a token for your account. For our guide we will pick the mordor.duckdns.org domain.

  2. Find your static IP address for your server. It does not matter the type of system or server you have, as long your VPS provider has given you an IP address to access it.

Bind IP

After you have signed in, and chose a free domain, you just have to enter your static IPv4 address to the current ip field and your static IPv6 address to the ipv6 field and press the update ip and update ipv6 buttons.

For example, for random IPv4 and IPv6 addresses:

domain current ip ipv6 changed
mordor 1.1.1.1 update ip 1:1:1:1:1:1:1:1 update ipv6 1 minute ago delete domain

After this, you should be able to access your server with the domain you created (mordor.duckdns.org for us), either with SSH or in the browser if you have a web server running.