Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dynamic DNS with Cloudflare - Python Script
# Set up a new A record in Cloudflare, add the details of it along with your account details below
# Make sure this script runs on startup (or whenever you get a new IP...)
# @author Aaron Rice <>
import urllib
import json
import sys
new_ip = urllib.urlopen("").read()
print "Error getting IP"
# Put your Cloudflare settings here.
# The host must be an A record that already exists in cloudflare
data = {
"a" : "DIUP",
"tkn" : "API_TOKEN_HERE",
"ip" : new_ip.strip(),
"z" : "DOMAIN_HERE",
dns_response = json.loads(urllib.urlopen("", urllib.urlencode(data)).read())
if dns_response[u'result'] == "success":
print "IP updated to " + new_ip,
print "Error Setting IP"
print "Error with cloudflare API"
Copy link

Hi Riceo,

May i ask what this script is, how it works ?

I'm trying to get cloudflare to work with my dynamic dns service for my website which uses

Does your script somehow make this possible ?

Copy link

riceo commented Jul 2, 2013


Sorry I haven't responded sooner - I had no idea you commented.

This was a quick hack for dynamic DNS via Cloudflare. If you run it as a cronjob on your server it will use the Cloudflare API to update your server's current public IP adress for the specified DNS entry on Cloudflare.

The change should only take a few minutes max to propagate.

I wouldn't trust it in a production environment, but it should work fine for testing / dev.

Let me know if you have any problems, and feel free to email me if I don't respond quick enough here!


Copy link

tiagoad commented Feb 11, 2014

Hey! I made a script similar to this, but it can update several hosts (like and

Check it out here:

Copy link

riceo commented Apr 12, 2014

@ttsda nice!

Copy link

nardev commented Jan 9, 2017

seems like parameters are changed now...

Copy link

riceo commented Nov 20, 2018

I'd imagine so!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment