Dynamic DNS with CloudFlare

  • So I have a dynamic DNS service for my ERL, but it's not in my actual domain. So I made a small script that updates my CloudFlare DNS from my ERL with their API. There is a cron job that just runs this script every 5 minutes.

    email="[email protected]"
    ip=$(ifconfig eth0 | grep "inet addr:" | cut -d: -f2 | awk '{ print $1 }')
    curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records/$recordID" \
         -H "X-Auth-Email: $email" \
         -H "X-Auth-Key: $key" \
         -H "Content-Type: application/json" \
         --data '{"type":"A","name":"'"$recordName"'","content":"'"$ip"'","ttl":120,"proxied":false}' -k

    You do have to get the record id from the API. I haven't found a way to get it through the web interface. So that means you have to create the record initially, either through the API or the web interface (or use an existing one). Once you have the ID, just paste it in the variable.

  • You can do this with a device on your LAN also. Instead of getting the IP from the interface just use something like

    ip=$(curl http://icanhazip.com)

  • @stacksofplates interesting that would work awesome. Gotta test it this week.

  • Service Provider

    Awesome, thanks.

Looks like your connection to MangoLassi was lost, please wait while we try to reconnect.