ddns-scripts: Support updating multiple A/AAAA records for the same domain
Nobody has claimed this yet.
- Dominant language
- Makefile
- Stars
- 4.6k
- Forks
- 4k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 134
Description
Maintainer: @<github-user> (find it by checking history of the package Makefile)
Environment: AArch64, Raspberry Pi 4B, OpenWrt 21.02.6
Description:
I have two WAN interfaces on my router, and currently I can use ddns to update their IP addresses to two different domains, e.g.:
wan1.example.com -> IP1
wan2.example.com -> IP2
Now I would like to use one domain name for both interfaces, for convenience and some load balacing, e.g.:
wan.example.com -> IP1, IP2
It's easy to do this manually at the DNS provider's (Cloudflare in my case) control panel by just adding multiple A/AAAA records for the same domain, but it seems not achievable by using ddns-scripts.
I tried adding two configs for ddns-scripts with the same domain but getting IP address from different WAN interfaces. It ended up with the two configs overwriting each other's DNS record (which makes sense since each config believes that its IP has changed). Also I tried writing a script reading both IP from the interfaces and setting it as IP source of the ddns config (modified from https://openwrt.org/docs/guide-user/services/ddns/client#detecting_wan_ip_with_script ):
#!/bin/sh
# path: /etc/ddns/get_wan_ips
. /lib/functions/network.sh
network_flush_cache
for WAN_IF in wan_1 wan_2
do
network_get_ipaddr NET_ADDR "${WAN_IF}"
echo "${NET_ADDR}"
done
config service 'cf_v4'
option service_name 'cloudflare.com-v4'
option use_ipv6 '0'
option enabled '1'
option lookup_host 'wan.example.com'
option domain 'wan@example.com'
option username '*REMOVED*'
option password '*REMOVED*'
option ip_source 'script'
option ip_script '/etc/ddns/get_wan_ips'
option interface '@wan_1'
option use_syslog '2'
option check_unit 'minutes'
option force_unit 'minutes'
option retry_unit 'seconds'
It didn't work either. The log (timestamp and domain/ip/id is removed/replaced):
: Detect local IP on 'script'
: #> /etc/ddns/get_wan_ips >/var/run/ddns/cf_v4.dat 2>/var/run/ddns/cf_v4.err
: Local IP 'IP1
IP2' detected via script '/etc/ddns/get_wan_ips'
: Update needed - L: 'IP1
IP2' <> R: 'OLD_IP1
OLD_IP2'
: parsing script '/usr/lib/ddns/update_cloudflare_com_v4.sh'
: Found Username 'Bearer' using Password as Bearer Authorization Token
: #> /usr/bin/curl -RsS -o /var/run/ddns/cf_v4.dat --stderr /var/run/ddns/cf_v4.err --capath /etc/ssl/certs --noproxy '*' --header 'Authorization: *REMOVED*' --header 'Content-Type: application/json' --request GET 'https://api.cloudflare.com/client/v4/zones?name=example.com'
: #> /usr/bin/curl -RsS -o /var/run/ddns/cf_v4.dat --stderr /var/run/ddns/cf_v4.err --capath /etc/ssl/certs --noproxy '*' --header 'Authorization: *REMOVED*' --header 'Content-Type: application/json' --request GET 'https://api.cloudflare.com/client/v4/zones/*REMOVED*/dns_records?name=wan.example.com&type=A'
: #> /usr/bin/curl -RsS -o /var/run/ddns/cf_v4.dat --stderr /var/run/ddns/cf_v4.err --capath /etc/ssl/certs --noproxy '*' --header 'Authorization: *REMOVED*' --header 'Content-Type: application/json' --request PUT --data @/var/run/ddns/cf_v4.dat 'https://api.cloudflare.com/client/v4/zones/*REMOVED*/dns_records/*REMOVED*'
WARN : CloudFlare reported an error:
: {"result":null,"success":false,"errors":[{"code":9207,"message":"Request body is invalid."}],"messages":[]}
ERROR : IP update not accepted by DDNS Provider
: Waiting 600 seconds (Check Interval)
The PUT request body is:
{
"id":"*REMOVED*",
"type":"A",
"name":"wan.example.com",
"content":"IP1 IP2",
"ttl":120,
"proxied":false
}
So the script just put two IPs into one request, while the Cloudflare API only accept one IP per PUT request to update a DNS record ( https://developers.cloudflare.com/api/operations/dns-records-for-a-zone-update-dns-record ).
I wonder if there's a method that I could update multiple A/AAAA records to the same domain with ddns-script. If it's not supported now, will it be a feature added in the future?
#16840 might be related to this, while it seems just update one of the records and skip others, rather than update many of them.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ddns-scripts configuration and the provider logic shown in /usr/lib/ddns/update_cloudflare_com_v4.sh; compare the behavior with the related issue #16840. Check how /etc/ddns/get_wan_ips supplies multiple addresses and how the Cloudflare request is assembled. Done means multiple A/AAAA values for one domain are handled as separate provider records without overwriting each other.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- devops, networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100