Skip to content

A simple Cloudflare Worker script to update your IP address using the build-in Fritz!Box DynDNS

License

Notifications You must be signed in to change notification settings

JavaScriptPlayground/cloudflare-worker-fritzbox-dyndns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare Worker Fritz!Box DynDNS

A simple Cloudflare Worker script to update your IP address using the build-in Fritz!Box DynDNS.

If you already have everything set up you can go directly to Using the script/request URL.


Why this script?

Why I did even wrote this script in the first place? There is already a service from AVM (the company behind Fritz!Box) called MyFritz! which does exactly that... Well, since I manage my domains with Cloudflare, I wanted to avoid an extra service where I need an extra account again. And since I already manage my domains via Cloudflare, I chose a Cloudflare Worker.

Info

If you already have a MyFritz! account from AVM and you are using this account actively, then you can use their own DynDNS service, which is provided directly by AVM.


What even is a Cloudflare Worker?

A Cloudflare Worker is basically just a script that is stored under a certain URL and is executed when this URL is called. Or rather, that's what we use it for. Cloudflare Workers can do so much more. For more info, check out this overview to see what else you can use Cloudflare Workers for.


Getting started

Okay, but now let's begin. In this guide I will explain how you can set up your own DynDNS service using a free Cloudflare Worker. I will go into all the steps that are necessary to create the Worker and how to set the service up correctly.

Create Account/Login

To get started you need a Cloudflare Acoount (if you don't already have one). Go to dash.cloudflare.com/sign-up to sign up or sign in with an existing account at dash.cloudflare.com/login.

Create first Worker

After you log in/register you should land on your dahboard. On the left hand side you should now see a menu point called "Workers". Click on this item. When you create a worker for the very first time you will land on the example page with the "Hello World sample worker" which looks something like this:

Build your first Worker

Click on "Create Worker" below.

Create Worker

Edit Worker

Then after that you will be taken directly to the "Quick Edit" view of the created Worker. On the left side you can see which code is executed inside the Worker. That means which code is responsible for our DynDNS service in the end. Now delete the code template example that was automatically added when you created it and replace it with the code from this repository.

Info

Optionally you can also use the minified version of the script.

After replacing the template with the code from the repository, click on the "Save and deploy" button at the bottom. If you have done everything right, you should be automatically returned to your account home page. Going again back to the left side in the menu under Workers, you should see your newly created Worker.

Newly created Worker

Quick-Edit existing Worker

You can edit your worker at any time using the "Quick edit" button.

Worker overview

Changing Sub-Domain for Workers

You can also change the sub-domain for all the Workers for your account. To do this, go back to the home page for all workers. Then on the right side you can change the sub-domain.

Change subdomain


Get and configure Cloudflare API Token

Next, we'll look at how you can generate an API token for your Cloudflare account. To do this, log into your account and go to your profile, at dash.cloudflare.com/profile.

My Profile

On the left side navigate to "API Tokens", under dash.cloudflare.com/profile/api-tokens.

Generate API Token

Now we will create a new API token. If you already have an API token from Cloudflare and it has the necessary permissions, then you can use this token.

Click on "Create Token"

Create API Token

Next, we will create a "Custom token" with the necessary permissions. To do this, click on Create Custom Token "Get started".

Create custom token

Give the token a name and then set these permissions for the token. You can also add more permissions, the important thing is that the token can be used to access your zone or the gateway API in the end.

Set permissions

Confirm the settings by clicking on "Continue to summary" below.

Continue to summary

Your summary should look similar to this. If so click on "Create Token"

Create Token

Now you can copy your token and use it for the Worker.

API-Token


Using the script/request URL

Next, we'll look at how to properly use the Worker's request URL. We will also take a look at how to correctly enter the update URL into your Fritz!Box.

Basic URL structure

Let's look at the basic structure of the request URL. The URL is structured as follows:

Worker subdomain Account name Cloudflare Worker domain
<subdomain> <name> workers.dev/
Info

An example would look like this: https://random-name.your-account.workers.dev/

URL parameters

The following parameters can be used in the URL:

Parameter Datatype Required Default Value Description
token string yes "" Token for the Cloudflare API
zoneid string yes "" ID for the DNS Zone
ipv4address string yes "" IPv4 address to update
ipv4name string yes "" IPv4 domain name
ipv4proxied boolean no true If the IPv4 connection should be proxied
ipv4ttl number no 1 IPv4 Time to live (1 = Auto, 60-86400 = Valid range)
ipv6address string no "" IPv6 address to update
ipv6name string (yes)* "" IPv6 domain name (*Only required if ipv6address is specified)
ipv6proxied boolean no true If the IPv6 connection should be prodied
ipv6ttl number no 1 IPv6 Time to live (1 = Auto, 60-86400 = Valid range)
comment string no "" Comment for the created/updated record

Parameters are simply appended to the request URL with a ?. Between the parameters are & characters. For more information, please reference to this article from MDN on how to properly encode URL parameters.

Placeholders

Furthermore, there are a few placeholders which are automatically replaced by the Fritz!Box:

Parameter Description
<username> Username
<pass>/<passwd> Password (Token)
<domain> Domain
<ipaddr> IPv4 address of the Fritz!Box
<ip6addr> IPv6 address of the Fritz!Box
<ip6lanprefix> IPv6 prefix for home network
<dualstack> Dual-stack
<useragent>* Device that sends the request (*This is not directly from Fritz!Box,
it is implemented via the Worker script)

For more information please reference to this knowledge base from AVM on "2 Setting up dynamic DNS".

Info

An example with the parameters would look like this:
https://random-name.your-account.workers.dev?token=abc1234&zoneid=1234&ipv4address=<ipaddr>&ipv4name=example.com&comment=This%20is%20a%20comment

Or with more placeholders:
https://random-name.your-account.workers.dev?token=<passwd>&zoneid=<username>&ipv4address=<ipaddr>&ipv4name=<domain>&comment=This%20is%20a%20comment%20from:<useragent>
Now you can put your credentials inside the password and username field.




About

A simple Cloudflare Worker script to update your IP address using the build-in Fritz!Box DynDNS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published