This script will take the settings in the .env file you provide (copy env.sample to .env to get started) and update Cloudflare with your public IP address so that traffic can be routed in a fairly stable manner back to your server/services behind your dynamic IP address.
- Copy env.sample to '.env'
- Edit the settings in the .env file as instructed by .env file
- Install poetry
- Run 'poetry install' (mine installs the virtual env in the ./.venv - yours may be different)
- activate the virtual env (e.g. poetry shell)
- Add A records in Cloudflare for the domains you want to point to your public IP (recommend using obviously bad IP addresses so you can check that they are updated correctly with your public IP address)
- Run the script
dyndns.py
(make sure it's executable) - Make sure it updated your IP addresses for your domains in Cloudflare
- It should have also created a CACHE.json file with identifiers it found for your zone and domains from Cloudflare
- Setup your cronjob to run every X minutes so that when your public IP address is updated, your servers will be updated within X minutes
Crontab command
*/5 * * * * /usr/bin/env bash -c 'cd /home/user/cf_dyndns && source .venv/bin/activate && ./dyndns.py'
NOTE: Update /home/user/cf_dyndns with the actual location of this script folder
Current public IP address endpoint - using this to find my public IP - more options are listed in StackOverflow question below