Bulk delete DNS records?

Lots of hits on the net about this; it seems that I have to figure out how to use the API, run an arbitrary script, and hope that it doesn’t mess up any of my other domains.

But surely there’s a proper way to do this?

Scenario: I had various domains with DNS at PointHQ. I’m rebuilding the server, and decided to move the DNS to Cloudflare. Some of the domains had no content and were parked on my server. So, when I was migrating everything, I temporarily left these domains pointing to the PointHQ DNS servers, but I deleted the DNS records at PointHQ.

Big, big mistake. A week later (today) I created the first parked domain at Cloudflare, and it tried to import the (non-existent) old records. It imported 501 records, all pointing to a dating site, which appears to be showing OnlyFans content (185.87.148.80; I’m not allowed to post the link here). I then tried a bulk import of the correct records, but it makes no difference; they’re just added.

Surely there has to be an approved simple way around this?

If you are on windows then you can use the following powershell script adding an API token with Zone:DNS:Edit permissions and your zone ID

$API_TOKEN = "<API TOKEN>"
$ZONE_ID   = "<ZONE ID>"

$baseUrl = "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records"

$headers = @{
  'Authorization' = "Bearer $API_TOKEN"
  'Content-Type'  = "application/json"
}

$listUrl = $baseUrl + '?per_page=500'
Write-Host $listUrl
$records = Invoke-RestMethod -Uri $listUrl -Method 'GET' -Headers $headers
$records = $records | Select-Object -ExpandProperty result

foreach ($record in $records) {
  Write-Host "Deleting $($record.name) that points to $($record.content)"

  $deleteUrl = $baseUrl + '/' + $record.id
  Invoke-RestMethod -Uri $deleteUrl -Method 'DELETE' -Headers $headers
  Write-Host $deleteUrl
}
1 Like

Thanks for the tip, but I don’t do Windows, so I went for Slayer’s script on github instead (which I can’t post a link to, for some reason). Nice and easy, had no problems with it, after jumping through the hoops of getting a token and a zone ID.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.