Skip to content

Instantly share code, notes, and snippets.

@slayer
Last active January 30, 2025 11:44
Show Gist options
  • Save slayer/442fa2fffed57f8409e0b23bd0673a92 to your computer and use it in GitHub Desktop.
Save slayer/442fa2fffed57f8409e0b23bd0673a92 to your computer and use it in GitHub Desktop.
Delete all DNS records for specified zone
#!/bin/bash
TOKEN="xxxxxxxxxxxxxxxxxxx"
ZONE_ID=2222222222222222222222222
# [email protected]
# KEY=11111111111111111111111111
# Replace with
# -H "X-Auth-Email: ${EMAIL}" \
# -H "X-Auth-Key: ${KEY}" \
# for old API keys
curl -s -X GET https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?per_page=500 \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" | jq .result[].id | tr -d '"' | (
while read id; do
curl -s -X DELETE https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${id} \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json"
done
)
@bjzhush
Copy link

bjzhush commented Apr 28, 2023

works perfect and thanks a lot !

@aianus
Copy link

aianus commented Jul 23, 2023

Thank you! Ridiculous that you can't add a new zone without copying all the old DNS records from the previous domain owner.

@dev-AshishRanjan
Copy link

Thanks,
The code works like a charm on wsl ubuntu
It took 3min to remove 600+ dns records

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment