![]() Write-Output "DNS record update successful." $Update = Invoke-RestMethod -Method PUT -Uri $uri -Headers $headers -SkipHttpErrorCheck -Body $body # Update the DNS record with the new IP address Write-Output "The current IP address does not match the DNS record IP address. # If the current IP address does not match the DNS record IP address, update the DNS record. # Compare current IP address with the DNS record Write-Output "Public IP Address: OLD=$($old_ip), NEW=$($new_ip)" Write-Output "DNS record : Type=$($record_type), IP=$($old_ip)" # Store the existing IP address in the DNS record Write-Output "Search for the DNS record return zero results. $DnsRecord = Invoke-RestMethod -Method GET -Uri $uri -Headers $headers -SkipHttpErrorCheck ![]() # Retrieve the existing DNS record details from Cloudflare. Write-Output "Domain zone : ID=$($zone_id)" Write-Output "Search for the DNS domain return zero results. $DnsZone = Invoke-RestMethod -Method GET -Uri $uri -Headers $headers -SkipHttpErrorCheck If the identifier is not found, the script will terminate. # Retrieves the domain's zone identifier based on the zone name. ![]() Write-Output "API token validation success. Write-Output "API token validation failed. $auth_result = Invoke-RestMethod -Method GET -Uri $uri -Headers $headers -SkipHttpErrorCheck # This block verifies that your API key is valid. These headers will be used throughout the script. Refer to the inline comments to understand what the script does. Copy the script below, paste it into your code editor, and save the file. Save the script inside the C:\CloudflareDDNS folder.ģ. Open your code editor, such as VSCode, and create a new PowerShell script file called Update-CloudflareDDNS.ps1. In this example, the script location is in C:\CloudflareDDNS.Ģ. Decide to which folder to store the script and create that folder if it does not exist yet. Saving the Scriptįollow the steps below to save the Cloudflare dynamic DNS PowerShell script on your client computer.ġ. This tutorial provides you with a working PowerShell script specifically for updating a DNS record in Cloudflare. What’s next? You’ll need to put the API token to use and integrate it with a script that would programmatically update the Cloudflare dynamic DNS record. You now have the Cloudflare account and the Cloudflare API Token with permission to edit a DNS zone. Verifying the API Token Setting Up the Cloudflare Dynamic DNS Update Script ![]() After logging in to the Cloudflare dashboard, click on the profile button on the upper-right corner and click My Profile. Open your browser, navigate to, and log in to your Cloudflare account.Ģ. To create a Cloudflare API Token, follow these steps.ġ. In turn, you can then use your Cloudflare account’s username and the resulting API token to authenticate with the Cloudflare API. Only then will Cloudflare allow you to make changes to the DNS records in your account.Ĭloudflare allows you to create API tokens with enough permissions for its purpose. When updating the Cloudflare dynamic DNS record programmatically, your script must authenticate itself to the Cloudflare API. But in this tutorial, you’ll be deploying a DNS updater script that runs on PowerShell 7.1. Third-party dynamic DNS services also exist that may be paid or free. Many dynamic DNS clients are available to install, mostly for Linux systems, like on an Ubuntu server or Raspberry PI. The DNS A record in this tutorial will be with an initial IP address of 0.0.0.0. You must have already added a DNS record under your domain in Cloudflare.You must have already added your domain to Cloudflare.A free account is enough to use in this tutorial. gq, are not applicable for Cloudflare dynamic DNS automation and will not work with this tutorial. The example domain in this tutorial is lazyexchangeadmin.cyou.įree top-level domains (TLD), such as. Related: What You Need to Know about Visual Studio Code: A Tutorial ![]() This tutorial will use Visual Studio Code v1.59.1 (recommended). Related: How to Walk Through a PowerShell 7 Upgrade This tutorial will use a Windows 10 computer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |