Do you want to update your DNS when your IP changes? Are you using a router running OpenWRT and Cloudflare? Then this short guide is perfect for you!
Let’s dive right into it. The OpenWRT router needs to modify your DNS settings on Cloudflare, so we need to create an API token. We could use the global API token, but we’ll use an API token with more limited access instead.
Creating a token on Cloudflare
Head to Cloudflare and go to My profile -> API Tokens -> Create Token -> Create custom token.
Give your token a name, e.g. OpenWRT DDNS and add the following permissions:
- Zone, Zone: Read
- Zone, DNS: Edit
Under Zone Resources, select Include, then Specific Zone and select your domain, e.g. example.com. Hit Continue to summary and then Create Token.
Remember to take note of this token as you’ll need it later.
Next up is configuring OpenWRT to work with Cloudflare. We’ll mostly use the Web GUI, but we’ll also SSH into the router to make a small change to how authentication is done with Cloudflare.
In the Web GUI, do the following:
- Go to System -> Software and press Update lists.
- Enter “ddns” into the filter field, and press Install on the
- Log out of the GUI and back in. You should now have a Services -> Dynamic DNS option. Go to it.
- Press Edit on
- Set DDNS Service provider to
cloudflare.com-v4and confirm the change.
- Then set Lookup Hostname and Domain to the domain you want to update, e.g.
example.com. Check the Enable and the Use HTTP Secure checkbox.
- Finally, paste the Cloudflare token you created into the Password field and hit Save and Apply. The username doesn’t matter.
The settings should now look something like this:
Great work, we’re almost done.
Next up, we’ll have to make a little change to the Cloudflare script as it doesn’t support authentication by using a token out of the box.
SSH into your router using, e.g. Putty. Use the same username and password that you have set up on your router. Then edit the script by running:
Enter insert mode by pressing i and find these lines:
__PRGBASE="$__PRGBASE --header 'X-Auth-Email: $username' "
__PRGBASE="$__PRGBASE --header 'X-Auth-Key: $password' "
Comment them out by adding a # at the beginning and add a new line below then so it looks like this:
#__PRGBASE="$__PRGBASE --header 'X-Auth-Email: $username' "
#__PRGBASE="$__PRGBASE --header 'X-Auth-Key: $password' "
__PRGBASE="$__PRGBASE --header 'Authorization: Bearer $password' "
The Authorization header is the new line. Cloudflare uses this header that will contain your token to identify you. Press Escape -> Type :wq -> hit Enter to save and quit. You can exit SSH now and go back to the GUI.
Change how your current IP is determined
If you head to Network -> Interfaces and you can see an IPV4-address under WAN, then OpenWRT knows what your current IP is, and you can skip this step.
However, if you don’t see an IP-address there, you’ll have to go to Services -> Dynamic DNS -> press Edit on myddns_ipv4 -> Go to Advanced Settings tab and change IP address source to something else.
Start using it
Now, head to Services -> Dynamic DNS and press Start.
Congratulations! 🎉 It should now be up and running. You can press Edit -> Log file viewer to view the log of what it’s doing.
If you have any questions, feel free to ask! 🙂