I use dietpi-ddns, but it bothers me, that it unnecessarily updates the IP address, although it hasn’t changed. Some DynDNS providers even limit the allowed updates per day.
I suggest to make a checkup before, whether the IP has changed since last update.
Below is an extended version of /var/lib/dietpi/dietpi-ddns/update.sh which uses upnpc from http://miniupnp.free.fr/ (apt install miniupnpc). To check for external ip you can use the command external-ip, which should be quite universal for all upnp routers. However, I use a fritz.box-specific command in line 2 to make the script faster. Another way without upnpc would be to use an external provider to check for the current external IP. But I wanted to limit the internet access and need for external services to a minimum.
So, here’s my productive script. Maybe it can be taken as an inspiration to extent dietpi-ddns.
Since IMO UPnP is a security issue, I have and recommend to everyone to disable it in router settings, we’d go with an external provider. Luckily we have our own + a function for it:
declare -F G_GET_WAN_IP
We didn’t implement it yet since from client perspective the IP check and the DDNS update are both simple tiny HTTPS requests. So doing the update itself does not cause more load then doing the check, i.e. the check actually adds additional load if the IP does differ.
DDNS providers limiting requests to something lower than 1 per minute is rare I think? At least none of the ones we implemented as hardcoded options has a limited anywhere near that strict.
But if it is more common, we can add the check as option of course.
Ah, and UPnP could be theoretically added as well as an option for the check. I remember we thought once to allow entering a custom command to retrieve the public IP, since there may be other options depending on network/router.
I see the point that requesting external DNS ist not much more than updating regardless. Still there’s the problem of limits by some providers, and the unnecessaryty, see below.
That’s why I’d like to encourage implementing the upnp option too. Maybe to choose from, external DNS or upnp. You CAN make upnp safe, so there’s no need to discriminate this in general. People are responsible for their own systems, and if they use upnp for any specific reason, let them. Me, I see questing external providers for my own IP an issue too. Security-wise, reliability-wise and data-protection-wise. In general, I don’t want to use external stuff when not principally necessary. And one provider (dyndns) to connect to is better than two (DNS + dyndns). So, there is pari-pari between “we recommend not using upnp” or “we recommend not using unnecessary external connections”. Let the system administrator choose, that’s HIS responsibility and the decision is strongly bound to his side conditions, skills and use case. Nothing that a developer can decide on his side.
Another idea: use any existing service that has the external IP already for it’s own purpose? Pihole comes to my mind. Problem: not everyone has it installed. Any other?
I don’t know, was just a blind guess, i’d think he needs it for it’s function? Maybe there’s something else already on the system? But anyway, we couldn’t make sure that it is up to date. So, maybe it was a bad idea.
PiHole don’t have such a feature. And we should not depend on such a service or a router functionality as we don’t know what has been installed and what is available inside network. We have quite a lot of user who even don’t know what features their router even have.
Therefore I would suggest to do a DNS request to verify current IP stored upstream and compare it with the actual external IP. If the are different, update DDNS.
@Joulinar there’s no either-or in my suggestion. Usage of upnp has advantages and should be an option for the user. Btw. the upnp scheme tells what services the router provides and how to access them. And that’s all already implemented in the command external-ip: figuring out the features of the router and access them. If it fails, fall back to external service or vice versa, but let the user choose.