CloudFlare, Dynamic IP - Case of a single-host environment. // PowerShell reddit / selfhosted ---------------------------------------------------------------------- GreatestTom · 2023-12-22 22:43 CloudFlare, Dynamic IP - Case of a single-host environment. // PowerShell Hello, in the link, I present a simple script that, upon execution, can update the IP for A records in Cloudflare if it has changed. ​ When run in CRON / Windows Task Scheduler at appropriate intervals, the script can update entries in CloudFlare in case of an external IP change. In each run, the script verifies whether the obtained IP matches the currently stored external IP. The script queries a list of defined services returning external IPs in a rotating cube / die fashion. Each time it starts querying the IP of the next service in the queue. In case of an error, it queries the next one until the list is exhausted. In the first run or when the external IP changes, the script verifies it with the entries in CloudFlare. If it encounters the same value, it terminates the script. If the IPs are different, it updates each entry with the correct external IP. For my private use with one server and one external IP, it works perfectly. PowerShell works on Windows/Linux/Mac and is well-suited for handling REST APIs, hence the choice. Please feel free to leave a comment or suggestions. [https://gitea.rdzen.net/najlepszytomasz/PowerShell/src/branch/main/Cl oudFlare/cloudflare\_ddns.ps1](https://gitea.rdzen.net/najlepszytomasz /PowerShell/src/branch/main/CloudFlare/cloudflare_ddns.ps1) ---------------------------------------------------------------------- certuna · 2023-12-22 22:55 This script only seems to update A records, not AAAA records? ---------------------------------------------------------------------- GreatestTom · 2023-12-22 22:57 yes, personaly i do not use AAAA (bcuz of using only ipv4 in my enviroment), but i can add/change it. ---------------------------------------------------------------------- Impossible-Check-684 · 2023-12-22 23:13 I run the below as a cronjob on one of my linux servers (same that runs NGIX), haven't had to touch cloudflare records in months: [https://github.com/NChaves/Cloudflare\_DNS\_API\_bash](https://github .com/NChaves/Cloudflare_DNS_API_bash) Not sure if this is something you could consider, depending on the devices you have available to yourself ---------------------------------------------------------------------- GreatestTom · 2023-12-23 05:43 Hi, Thank you very much for sharing a similar tool. From the provided script, I can borrow another page to retrieve IP addresses in case of a failure with any of the already defined ones. 'http://ipinfo.io/ip' 'http://ifconfig.me/ip' 'http://icanhazip.com' 'http://ident.me' Both are relatively interchangeable. Having more pages returning IP addresses allows for more frequent verification of the public IP address. With 5 requests every 5 minutes, there's a 25-minute interval between querying individual pages. An additional advantage, in my opinion, is that it retrieves proxy information from CloudFlare. Records using the proxy will benefit, while those not using it won't. ---------------------------------------------------------------------- mcmron · 2023-12-23 06:24 You can hit [https://ip2location.io/ip](https://ip2location.io/ip) for IP address. ---------------------------------------------------------------------- GreatestTom · 2023-12-23 11:05 If more then better! Especially when it goes forward when cannot reach firsts one and so on. Thx. ---------------------------------------------------------------------- Impossible-Check-684 · 2023-12-23 11:25 I do run a few Linux server, found it easier to just create a bash script for that. The script does check that the response from "api.ipify.org" is a valid IP using regex, only if of the proper format will it then make any changes. Not a bad idea to check against multiple sources, if I ever find an issue (none in almost an year, since I last update the script) I shall look into had some more fallbacks. ---------------------------------------------------------------------- GreatestTom · 2023-12-23 11:40 Using multiple addresses allows for proper functioning by refreshing the configuration, regardless of whether any of the services are available or not. They also enable increased frequency of querying the correct IP without imposing significant load on external services. I understand that many users may utilize them for this purpose. Some may have query limits per unit of time. By logging each occurrence, I've noticed that one service, http://icanhazip.com, doesn't always return information about the external IP. ---------------------------------------------------------------------- Impossible-Check-684 · 2023-12-23 12:53 Fair point, not sure I've come across that with ipify!