Skip to content

Instantly share code, notes, and snippets.

@taichikuji
Last active February 23, 2025 13:26
Show Gist options
  • Save taichikuji/6f4183c0af1f4a29e345b60910666468 to your computer and use it in GitHub Desktop.
Save taichikuji/6f4183c0af1f4a29e345b60910666468 to your computer and use it in GitHub Desktop.
Get a DDNS up and running with DuckDNS - Step by Step

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

Understanding DDNS

In summary, DDNS stands for Dynamic DNS. DDNS updates a DNS name in real-time to point to a changing IP address. This is useful for devices without a static IP. For example, companies like Google use static IPs and IP ranges, which are more expensive than ephemeral IPs and IP ranges. DDNS provides a cost-effective alternative, linking a hostname to a dynamic IP address.

How Does DDNS Work?

To use DDNS, you need an account with a DDNS provider. While some services are paid, they are still cheaper than static public IPs from ISPs. A script or service on your device updates the DDNS server with your current IP at regular intervals to maintain the link between your hostname and IP address. Luckily for us, DuckDNS is free for everybody and relays on donations to keep their services running.

Please go ahead and donate to DuckDNS' patreon if you enjoy their services.

Setting Up DuckDNS

As mentioned, we'll use DuckDNS for this guide.

  1. Create an Account and Login: Visit DuckDNS and log in or create an account.

img

  1. Create a Domain: Once logged in, create a domain and link it to your current public IP.

img

Automating IP Updates with a Script

DuckDNS provides a simple script to keep your domain updated with your dynamic IP.

img

You can go ahead and follow their guide, or continue reading;

  1. Ensure crontab is Running:

    ps -ef | grep cr[o]n
  2. Check if curl is Installed:

    curl --version

    If not, install it on Ubuntu/Debian systems:

    sudo apt install curl -y
  3. Create a DuckDNS Script:

    • Navigate to your home directory and create a duckdns folder:
      cd ~
      mkdir duckdns
      cd duckdns
      touch duck.sh
  4. Edit the Script:

    • Open the script with nano or your preferred text editor and add the following line:
      #!/bin/bash
      DOMAIN="EXAMPLE"
      TOKEN="TOKEN"
      echo url="https://www.duckdns.org/update?domains=$DOMAIN&token=$TOKEN&ip=" | curl -o ~/duckdns/duck.log -K -
    • Replace EXAMPLE with your DuckDNS domain and TOKEN with your unique token found on the DuckDNS dashboard at the top of the script. On line 2-3.
  5. Set File Permissions and Schedule the Script:

    • Make the script executable:
      chmod +x ~/duckdns/duck.sh
    • Open crontab to schedule the script:
      crontab -e
    • Add the following line to run the script every 5 minutes:
      */5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1
  6. Run the Script Manually for the First Time:

    • Navigate to the script directory and execute it:
      cd ~/duckdns/
      ./duck.sh
    • Check for the creation of duck.log. If it contains "OK", the setup is successful. If it displays "KO", there was an issue. You may want to revise that everything is correctly configured before proceeding further.

Next Steps

Just as an example, but you may want to set up port forwarding on your router to utilize your new DDNS hostname effectively.

@taichikuji
Copy link
Author

On this page 2024-06-30_150517_km

There may be some confusion. I feel like, for changes on the DuckDNS service itself you should reach out to the DuckDNS team directly, not to me.

They seem to have the following email available for support, so you may want to try your luck over there; support@duckdns.org

Hope that helps! :)

@aquariustech12
Copy link

@littlegreenbean33
Copy link

hi, is there any way to create an account/login with email ?

@taichikuji
Copy link
Author

hi, is there any way to create an account/login with email ?

https://www.duckdns.org/login?generateRequest=persona

Seems like you cannot anymore. You will have to choose any other login option available by them.

@chrisl8
Copy link

chrisl8 commented Feb 22, 2025

May I kindly suggest removing the -k from your curl command? That is telling curl to run in an insecure way:
https://curl.se/docs/manpage.html#-k

I realize that in some cases for some users it may help to deal with a local misconfiguration, but it should not be used by default.

@taichikuji
Copy link
Author

May I kindly suggest removing the -k from your curl command? That is telling curl to run in an insecure way: https://curl.se/docs/manpage.html#-k

I realize that in some cases for some users it may help to deal with a local misconfiguration, but it should not be used by default.

You are absolutely correct. I removed the flag now. The flag was initially added as it was suggested by duckdns's maintainer.

Thank you!

@ivanprea
Copy link

Hi, everyone i don't know if i'm in the right place but i'm facing some issue with duckdns. I''m a boob of it so it might be something that i do wrong, but it's like 2 weeks that i'm setting up my "server" and i created some domain then SSL certificate. Since yesertady the website of duckdns where i have my 2 domains when i close the tab/window change the IP address by itself. So now i can't connect anymore to my server via dns and https but only by typing the ip address. Can someone help me out to understand what i'm doing wrong? if i'm in the worng place to ask this please let me know and i will delete this comment. Thank you

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