TXK57 32 Posted September 28, 2021 Share Posted September 28, 2021 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' You will want to use the 'Edit zone DNS' template or select 'Create Custom Token' Here you will want to allow Zone Read access and Zone DNS Edit rights. It will then take you to a summary page, select 'Create Token' You will now have the generated API Secret. Copy API Token into the script Copy your Zone ID Go back to the main home page of your Cloudflare dashboard and select your domain Scroll down and towards the bottom right you will find the API section. You want to copy the Zone ID 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. 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'. Go to the next tab and create a new 'Trigger'. I choose to run mine hourly. 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" 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 1 Link to comment Share on other sites More sharing options...
Luke 37062 Posted September 28, 2021 Share Posted September 28, 2021 Thanks for sharing. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now