Jump to content

DDNS for free with PowerShell


TXK57

Recommended Posts

I wanted to share a PowerShell script with everyone. This can be ran as a scheduled task on a Windows box, and will update your DNS entry in Cloudflare via API. This is much better then paying for a DDNS service, and you can use your own domain.

Make sure you have already purchased a domain and have your domain's DNS setup in Cloudflare.

Step 1: Create a path on your hard drive for this script. For this example I'm going to use C:\Scripts. Copy the script to this path and open it with your favorite editor. I use Notepad++.

Step 2: Create you Cloudflare API token https://developers.cloudflare.com/api/tokens/create

To create an API for your script login to your Cloudflare account at https://dash.cloudflare.com/login. Then go to User Profile/API Tokens https://dash.cloudflare.com/profile/api-tokens.

From the API Token dashboard select 'Create Token'

image.png.96cfbee45d9eb7acb3a9089a2b7ef8d5.png

 

You will want to use the 'Edit zone DNS' template or select 'Create Custom Token'

image.png.a6f8f6ed92f622179c5e411669b22480.png

 

Here you will want to allow Zone Read access and Zone DNS Edit rights.

image.png.d5335b5f38579b8cb9b47a74c694e3ec.png

 

It will then take you to a summary page, select 'Create Token'

image.png.efc9ff35132adad42035b672db6cfb08.png

 

You will now have the generated API Secret.

image.png.c691080cd562eaed98825b5228be9668.png

Copy API Token into the script

image.png.a6549b165b871b6088fcb872cf71e633.png

 

Copy your Zone ID

Go back to the main home page of your Cloudflare dashboard and select your domain

image.png.2168bf75d5cf1c043e4aa305362829bc.png

Scroll down and towards the bottom right you will find the API section. You want to copy the Zone ID

image.png.587ab037c59b6f0c0711c556f740472c.png

image.png.8775eadff50c5b685fcbdf728973f506.png

Add which record you want to change. I typically update my main domain I have for emby and then all my other records are CNAME that point back to the same IP.

Note: Make sure you are proxying your traffic to mask your actual IP.

Step 3: Create a task in task scheduler

Open task scheduler on windows. I typically create an Automation folder to keep my tasks separate from Windows and Applications.

image.png.d326630445f18cf481ed1ee258ec62b9.png

Once you have your Automation folder, select that folder and 'Create Task'. Name the task anything you like. I chose to name mine 'Cloudflare DNS Update'. Also change the user to run as 'System'.

image.png.748908208973f3c24d87352cc223180a.png

Go to the next tab and create a new 'Trigger'. I choose to run mine hourly.

image.png.333084f38eb89f630487f783616484e0.png

You now want to create an 'Action'. You want to 'Start a program'. The program is 'powershell.exe'. For the argument you want '-File "C:\Scripts\updateCloudflareDNS.ps1"

image.png.e733adbca225c98076aa833bdf5722b5.png

 

That is it, the task will now execute the script to check your external IP and update your DNS record for you. Issues and updates will be logged wherever this script is. So for this example it would be in C:\Scripts\updateCloudflareDNS.log.

 

 

 

updateCloudflareDNS.ps1

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...