Skip to content

Instantly share code, notes, and snippets.

Last active August 22, 2023 22:32
  • Star 17 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Get a DDNS up and running with DuckDNS - Step by Step

Get a DDNS up and running with DuckDNS - Step by Step

DDNS? What is that?

A dynamic DNS. DNS stands for Domain Name Server, which, in other words, is basically the server that answer your queries when you search for a hostname on the internet.

Example: If you search for "" there will always (probably) a server that points out to that hostname and tells you the information the computer needs; the IP address.

If you want to give it a test, you only have to open your terminal and type "ping" and you will see the real IP address appear! In my case it's .

Anyways.. A DDNS is useful if you want to link or put a hostname to an IP that is not STATIC.

You see.. Google and other companies usually have STATIC IP addresses. It's easier to control and use. Only issue is that these are expensive. For someone who wants to get something static without having to ask their ISP for a bigger contract (and much more expensive) that involves your IP being static, you should look for dynamic DNS services.

What these do is the same as a normal DNS, they link a hostname to an IP address, but a DDNS has a twist.

A DDNS allows you to have a dynamic ip in combination to the static hostname linked!

But how does it work?

Okay, so basically you sometimes need some kind of account linked to your persona to use that service, and sometimes it's not free (it's still way cheaper than having an STATIC PUBLIC IP on our router). You will also need the "server" to interact every x amount of time with the Dynamic DNS server so that they can make sure you always have the proper IP linked to the STATIC url.

Okay, so how do I do this?

Since you will need a server anyways or some device to host whatever you want to have, you should use that device or a similar one to interact with this server through a script. It depends on the service you use, but in our case i will be using DuckDNS.

If we visit DuckDNS's website, we will see something like this;


What we will need to do is basically create an account, or login if we already have one. After that, something like this should appear;


We can create a domain here, call it however we want and give it our current public ip.

Done! or are we? I mean, it's not going to update anything currently. The second our ISP changes our Dynamic Public IP, this will not work anymore.

That's why I mentioned an automated script before. DuckDNS allows us to use a really simple script using cron (crontab). After we create our first domain, we need to head up to the "install" tab and follow the steps.


In my case I will be using "pi" or "linux cron", they're almost the same.

Following the tutorial we just have to do these steps;

  1. First of all we need to execute this command to make sure we have crontab running already.

ps -ef | grep cr[o]n

  1. After that, we should test if we have curl installed writting "curl" onto the terminal. If it returns some error mentioning curl not being installed we shall install it. On Ubuntu/Debian systems you can install it like this;

sudo apt install curl -y

  1. If we already have it installed, or we just installed it right now, we now have to create the script itself. We can create anywhere where our user has the ability to create and modify files. In my case I'll create it here; ~/duckdns/

    To create those we will execute the following commands;

cd ~

mkdir duckdns

cd duckdns


  1. After that, we have to modify our file. We can use whatever we want as a text editor but I will be using nano. We open the file and put this following information;

     echo url="**EXAMPLE**&token=**TOKEN**&ip=" | curl -k -o ~/duckdns/duck.log -K -

    As you can see, you have two values that are generic (aka EXAMPLE and TOKEN). These values are unique to the persona that is going to use it.

    The example value is basically the name or domain you used. The token value is the value shown in the initial webpage of DuckDNS after logging in for the first time. You can see it here;


  1. After this, we shall add executable permissions on the script and then add it to our crontab. First, the permissions;

    chmod 700 ~/duckdns/

    Then we do;

    crontab -e

    And we add this one liner at the end of the file that will open after executing crontab -e;

    */5 * * * * ~/duckdns/ >/dev/null 2>&1

    After this, we should execute the script once manually just to see it working;

    cd ~/duckdns/


    If we then find a new file created called "duck.log" with "OK" inside, everything worked properly!

What now?

Well you probably want to setup port forwarding on your router to make use of your new DDNS hostname.

Copy link

Your guide is correct, when I ping my subdomain in Windows CMD, it says that my vps IP does not change, and the IP has not changed, and it shows OK in the Linux terminal.

Copy link

How do we check if a new file is created with "OK" inside? Coding noob here.

Copy link

How do we check if a new file is created with "OK" inside? Coding noob here.

In order to check it, you can run the cat ./duck.log to show the logging output through terminal. You can also manually open it with any text editor!

Copy link

For anyone that is not a genuine git-hub user, the only authentication method available is google.
Persona & reddit support has been removed & Twitter does not work.
I had created a free machine account on github as this would be an automated process however, the account was suspended with the following explanation. "GitHub is meant to be used as a collaborating and hosting tool for software developers. We're unable to see activity on your account that indicates that it's being used for the intended purpose." This does not seem unreasonable.

Copy link

A docker solution would be cleaner :-)

Docker-abstraction-layer for a curl-command.
Yeah sounds absolutely reasonable.

Copy link

n8jadams commented Aug 18, 2023

No need to abstract this out into its own .sh script. Just run

crontab -e

And then add this line to your crontab file

*/5 * * * * curl "" >/dev/null 2>&1

Save it and you're done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment