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.
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.
As mentioned, we'll use DuckDNS for this guide.
- Create an Account and Login: Visit DuckDNS and log in or create an account.
- Create a Domain: Once logged in, create a domain and link it to your current public IP.
DuckDNS provides a simple script to keep your domain updated with your dynamic IP.
You can go ahead and follow their guide, or continue reading;
-
Ensure
crontab
is Running:ps -ef | grep cr[o]n
-
Check if
curl
is Installed:curl --version
If not, install it on Ubuntu/Debian systems:
sudo apt install curl -y
-
Create a DuckDNS Script:
- Navigate to your home directory and create a
duckdns
folder:cd ~ mkdir duckdns cd duckdns touch duck.sh
- Navigate to your home directory and create a
-
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 -k -o ~/duckdns/duck.log -K -
- Replace
EXAMPLE
with your DuckDNS domain andTOKEN
with your unique token found on the DuckDNS dashboard at the top of the script. On line 2-3.
- Open the script with
-
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
- Make the script executable:
-
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.
- Navigate to the script directory and execute it:
Just as an example, but you may want to set up port forwarding on your router to utilize your new DDNS hostname effectively.
If you use this shell script instead, you can also update your ipv6
#!/bin/bash domain=mydomain token=aaaabbbb-cccc-4444-8888-ddeeff001122 ipv6addr=$(curl -s https://api6.ipify.org) ipv4addr=$(curl -s https://api.ipify.org) echo "https://www.duckdns.org/update?domains=$domain&token=$token&ip=$ipv4addr&ipv6=$ipv6addr" curl -s "https://www.duckdns.org/update?domains=$domain&token=$token&ip=$ipv4addr&ipv6=$ipv6addr" -o ~/duckdns/duckdns.log
(source: https://superuser.com/questions/1634497/how-to-publish-ipv6-on-duckdns)