I have struggled a bit with setting up duckdns on the RPi, but got there in the end. Here’s what I did.
I wanted use a dns service to access IOT units in my house and wanted the RPi to talk to the duckdns server every five minutes to keep my domain on the duckdns pointing at the correct IP. The instructions on the duckdns site are a bit opaque to ordinary mortals and didn’t quite work for me.
I tried using sudo in front of the commands but it made no difference, so it is not necessary.
1. Create a script file on the Rpi to contact the duckdns site. Create a directory and then the file. Do this in your home directory, /home/pi, usually. Open a terminal window and type - mkdir duckdns, after the prompt, mine is [email protected]
pi ~$ mkdir duckdns
then go to that directory
pi ~ $ cd duckdns
create the script file using nano , by typing - nano duck.sh
pi ~ /duckdns $ nano duck.sh
Now you need the name of the domain you created when you signed up to duckdns say MYIOT and the long token, or security code you were issued with, something like
The script file will call the program curl, a command line tool that will send data or request data from a server, in this case duckdns.org. The instruction curl is to use is piped to it using the echo command. You need to put in the path to your duckdns directory as it appears on your computer. On my machine this /home/pi. So enter precisely,
echo url="https://www.duckdns.org/update?domains= ... 4a50f2&ip=
" | curl -k -o /home/pi/duckdns/duck.log -K –
all in one line, replacing the domain name, the token and path with your values. Pay attention to the quotation marks, spaces, vertical line, the & symbols. The various parameters after the curl command are directives, google for details. A log file, duckdns.log, is created, which is overwritten each time (single >), with the results of the curl call. All it will contain is ”OK”, if it is successful. You can use leafpad to edit the script file and cut and paste from the duckdns web site if you find this easier.
(If like me you want to check it runs every five minutes for the first few days, add a second line to the script file
date >> /home/pi/duckdns/time.log
This will add to the time.log file each time the script runs, (>> ) with the date and time the script ran. This file will grow and grow, so delete the line from the script, once you are happy it is running.)
Close nano with CTRL X, y, Return.
2. Make the script an executable file, by typin g- chmod 700 duck.sh
pi ~ /duckdns $ chmod 700 duck.sh
It is best to test the file works, type - ./duck.sh
pi ~ /duckdns $ ./duck.sh
It should return something like
%Total % Received % Xfred Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2 0 2 0 0 0 --:--:-- 0:00:02 --:--:-- 1
pi ~ /duckdns $
Then have a look at the log file, type cat duck.log
pi ~ /duckdns $ cat duck.log
OK [email protected]
pi ~ /duckdns $
Note the “OK” at the start of the line, the conents of the file. That shows it is working.
3. Set up program cron to run this script at 5 min intervals by editing the text file that drives cron by typing, crontab -e
pi ~ /duckdns $ crontab -e
This will open a text editor and show the current contents with several lines of instructions with # to indicate comment lines. There may be data lines at the end of these, go to a the start of a blank line below everything and enter precisely
*/5 * * * * /home/pi/duckdns/duck.sh >/dev/null 2>&1
Again noting the spaces and replacing the path with the correct one for your machine. This tells cron to run the script , duck.sh, every 5 min and send the output and any error messages(2>&1) to a an empty file (null). I found I had to put in the full path to get it to work, unlike the instructions on duckdns.org, which used the path shortcut “~”.
Exit the editor using Ctrl X, y, Return. Assuming all is correct you should see,
pi ~$ crontab –e
crontab: installing new crontab
To check it is working look at the date on the duck.log file, or delete the log file and see when it is created again. (If you added the date line to script file, look at the time.log file, using
pi ~$ cat time.log
or viewing it in leafpad.)
Hopefully not to long winded, but I wanted to explain the steps so you can trace faults more easily.