I had implemented a solution for this.
I'm using
- dynu a dinaminc DNS service because it has support to web and mobile app
- cloudflare workers
- digital ocean firewall
Dinamic DNS
My internet provider service has dynamic IP, eveny time that my IP change the service will set my updated ip into a subdomain domain namaged by Dynu. So any one the know about the sudmain name now can retrive my IP address.
Cloudflare Workers
Cloudflare Workers is a serverless service that allow cron run a script. The script will get the list with all IPs that cloudflare do proxy, and resolve the subdomain to get my IP address.
With all these IPs i update the digital ocean firewall adding/updating two firewall rules:
- allow only at port 80 and 443 to cloudflare ips.
- allow all ports (TCP and UDP) to ip address resolved by subdomain nameged by dynu
You can use any DNS service to do it, and you can use any serverless service too. the one hard is digital ocean firewall to you replace.