How to use cloudflare to host Azure domain names

致帮 姜 20 Reputation points
2024-03-18T06:40:03.9266667+00:00

I registered a domain name on Azure, but I want to use cloudflare to host it. However, Azure currently cannot modify the default four name servers, so I cannot replace CloudFlare's name servers. Is there any solution?

User's image

Azure DNS
Azure DNS
An Azure service that enables hosting Domain Name System (DNS) domains in Azure.
591 questions
{count} votes

Accepted answer
  1. TP 74,131 Reputation points
    2024-03-18T09:50:26.5+00:00

    Hi,

    Please follow instructions below to switch your name servers to Cloudflare:

    A) On your local Windows PC, install latest Az PowerShell module if you do not already have it installed:

    https://learn.microsoft.com/en-us/powershell/azure/install-azps-windows?view=azps-11.4.0&tabs=windowspowershell&pivots=windows-psgallery

    B) In the portal, find and copy Azure Subscription ID where your domain name is. You will need it for script below. Your Subscription ID can be found by navigating to your Subscription -- Overview tab.

    C) Copy/paste below script into Notepad, next replace Subscription ID on top line with your Subscription ID. Once you have done that you may open a PowerShell window and copy/paste the script from Notepad into the PowerShell window to start executing it.

    $subscriptionID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    Connect-AzAccount
    Set-AzContext -Subscription $subscriptionID
    $token = (Get-AzAccessToken).token
    $headers = @{"Authorization" = "Bearer $token"}
    $uri = "https://management.azure.com/subscriptions/$subscriptionID/providers/Microsoft.DomainRegistration/generateSsoRequest?api-version=2022-03-01"
    $response = Invoke-WebRequest -Method Post -Uri $uri -Headers $headers
    $json = $response.Content|ConvertFrom-Json
    $dccUrl = $json.url
    $dccPostParameterKey = $json.postParameterKey
    $dccPostParameterValue = $json.postParameterValue
    $htmlFile = @"
    <!DOCTYPE html>
    <html>
    <head>
    <title>Domain Control Center</title></head>
    <body onload="submitSSOForm()">
    <form id="ssoForm" method="post" action="$dccUrl">
    <input type="hidden" name="$dccPostParameterKey" value='$dccPostParameterValue'>
    </form>
    <script>
    function submitSSOForm() {document.getElementById("ssoForm").submit();}
    </script>
    </body>
    </html>
    "@
    $htmlFile|Out-File ./DomainControlCenter.html
    Invoke-Item ./DomainControlCenter.html
    
    

    You will be prompted to sign in to Azure, make sure you use account with enough permission (e.g. Owner). After signing in the script will run for several seconds and then your default browser will open. Please note I only tested using Edge. After the browser opens there will be another brief delay and then Domain Control Center will display your Domain(s):

    qna dcc domain list edit nameservers

    Click on the context menu (three dots), then click Edit nameservers.

    On Edit nameservers screen, click the trash can icon to delete unnecessary lines as needed:

    qna dcc domain list edit nameservers delete lines

    Next edit the remaining lines and set them to your Cloudflare name servers. You may view the name servers you need to enter on your Cloudflare dashboard -- Websites -- <yourdomain>. When finished it should look similar to below, then click Save.

    qna dcc domain list edit nameservers cloudflare

    There will be a delay for the change to propagate. You may check periodically in Cloudflare to see if it is active.

    Please click Accept Answer and upvote if the above was helpful. If something is unclear please add a comment below.

    Thanks.

    -TP

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful