How can I configure cloudflare-ddns on my raspberry pi 4 as a dynamic DNS to update my…
- User
How can I configure cloudflare-ddns on my raspberry pi 4 as a dynamic DNS to update my cloudflare A record?
- Assistant
To configure cloudflare-ddns on your Raspberry Pi 4 to update your cloudflare A record, follow these steps:
- Install cloudflare-ddns on your Raspberry Pi 4:
sudo apt-get install git python3 python3-pip python3-venv sudo git clone https://github.com/clinta/cloudflare-ddns.git cd cloudflare-ddns sudo python3 -m venv env sudo env/bin/pip install -r requirements.txt- Edit the configuration file
config.json:
sudo nano config.jsonHere is an example of a configuration file:
{ "cloudflare": { "email": "your-email@example.com", "api_key": "your-api-key" }, "zone": { "name": "example.com", "record_name": "home.example.com" } }Replace
your-email@example.comwith your Cloudflare email address,your-api-keywith your Cloudflare API key,example.comwith your domain name, andhome.example.comwith the A record you want to update.- Run the script:
sudo env/bin/python3 cloudflare_ddns.pyThis will update the A record in Cloudflare. You can check the DNS settings in your Cloudflare dashboard to ensure that the A record has been updated.
- Set up a cronjob to run the script every 10 minutes:
Edit the cron file:
sudo crontab -eAdd the following line to run the script every 10 minutes:
*/10 * * * * cd /path/to/cloudflare-ddns && sudo env/bin/python3 cloudflare_ddns.py >/dev/null 2>&1Replace
/path/to/cloudflare-ddnswith the absolute path to the directory where you installed cloudflare-ddns.That's it! Your Raspberry Pi 4 will now update your Cloudflare A record every 10 minutes.
- User
I do not want to use my cloudflare global API key, I would like to use zone token API key
- Assistant
To use the zone token API key instead of your global API key, follow these steps:
-
Create a new API token in your Cloudflare account that has the
Zone.Zone SettingsandZone.Zonepermissions. This will allow the token to update DNS records in your selected zone. -
Edit the
config.jsonfile to include the zone token API key instead of your global API key:
sudo nano config.jsonHere is an example of a configuration file with a zone token API key:
{ "cloudflare": { "email": "your-email@example.com", "api_key": "", "api_token": "your-zone-token" }, "zone": { "name": "example.com", "record_name": "home.example.com" } }Notice that instead of an
api_keyattribute, there is now anapi_tokenattribute. Replaceyour-zone-tokenwith the API token you created in step 1.- Run the script as before:
sudo env/bin/python3 cloudflare_ddns.pyThis will update the A record in Cloudflare using the zone token API key you specified.
- Set up the cron job as before, using the same updated command:
*/10 * * * * cd /path/to/cloudflare-ddns && sudo env/bin/python3 cloudflare_ddns.py >/dev/null 2>&1That's it! Your Raspberry Pi 4 will now update your Cloudflare A record using the zone token API key.
-
- User
do I need to use the zone's token name at all in the config?
- Assistant
No, you do not need to use the zone's token name in the config. Only the API token itself is required.
Here is an example
config.jsonfile using just the API token:{ "cloudflare": { "email": "your-email@example.com", "api_token": "your-zone-token" }, "zone": { "name": "example.com", "record_name": "home.example.com" } }Replace
your-zone-tokenwith your actual Cloudflare API token.Alternatively, you can use both the API key and the API token in the
cloudflaresection of theconfig.jsonfile. The script will try to use the API token first if it is present, and fall back to the API key if the token is not found.Here is an example
config.jsonfile using both the API key and the API token:{ "cloudflare": { "email": "your-email@example.com", "api_key": "your-global-api-key", "api_token": "your-zone-token" }, "zone": { "name": "example.com", "record_name": "home.example.com" } }Replace
your-global-api-keyandyour-zone-tokenwith your actual values.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.