OpenWRT DDNS with Linode API v4

Here's how I was able to use OpenWRT's native DDNS system with Linode API v4. It works well for me and might work well for others.

/usr/lib/ddns/update_linode_com_v4.sh

# Script for sending user defined updates using the Linode v4 API
# 2015 Artem Yakimenko <code at temik dot me>
# 2021 George Giannou <giannoug at gmail dot com>
# 2024 bluonek  <https://forum.openwrt.org>

# Options passed from /etc/config/ddns:
# domain - Linode domain id (e.g. 1325552)
# password - Linode personal access token (API key)
# param_opt - Linode API record ID of the A/AAAA record (e.g. 21694203)

# Use the following command to find your Linode API domain ID (replace TOKEN with your own):
# curl -X GET -H 'Content-Type: application/json' \
#     -H "Authorization: Bearer TOKEN" \
#     "https://api.linode.com/v4/domains"

# Then use the following command to find your Linode API resource ID (replace TOKEN with your own, and DOMAIN with the domain ID from the previous command):
# curl -X GET -H 'Content-Type: application/json' \
#     -H "Authorization: Bearer TOKEN" \
#     "https://api.linode.com/v4/domains/DOMAIN/records"

. /usr/share/libubox/jshn.sh

[ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing domain name as 'Domain'"
[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing personal access token as 'Password'"
[ -z "$param_opt" ] && write_log 14 "Service section not configured correctly! Missing API domain resource ID as 'Optional Parameter'"

# Construct JSON payload
json_init
json_add_string target "$__IP"

__STATUS=$(curl -Ss -X PUT "https://api.linode.com/v4/domains/${domain}/records/${param_opt}" \
    -H "Authorization: Bearer ${password}" \
    -H "Content-Type: application/json" \
    -d "$(json_dump)" \
    -w "%{http_code}\n" -o $DATFILE 2>$ERRFILE)

if [ $? -ne 0 ]; then
    write_log 14 "Curl failed: $(cat $ERRFILE)"
    return 1
elif [ -z $__STATUS ] || [ $__STATUS != 200 ]; then
    write_log 14 "Curl failed: $__STATUS \nlinode.com answered: $(cat $DATFILE)"
    return 1
fi

/etc/config/ddns

config ddns 'global'
    option ddns_dateformat '%F %R'
    option ddns_loglines '250'
    option ddns_rundir '/var/run/ddns'
    option ddns_logdir '/var/log/ddns'

config service 'your_domain_com'
    option lookup_host 'your.domain.com'
    option domain '1325552'
    option password 'your_token_goes_here'
    option param_opt '21694203'
    option update_script '/usr/lib/ddns/update_linode_com_v4.sh'
    option interface 'wan'
    option ip_source 'network'
    option ip_network 'wan'
    option use_https '1'
    option use_syslog '1'
    option cacert '/etc/ssl/certs'
    option use_ipv6 '0'
    option check_interval '1'
    option check_unit 'hours'
    option enabled '1'

1 Reply

Thank you for sharing your configuration on how you were able to use OpenWRT's native DDNS system with Linode API v4! We appreciate your efforts in passing this along. I've also provided some additional resources for any other users who would like to get started with OpenWRT:

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct