Bulk delete DNS record?

Heyas, I just added my domain, and this “quick scan” thingy added 1000 DNS entries… It’s counting up like 1,2,3,4,5,6,7… and so on…

How can I get rid of all thes entries? deleting them one by one takes ages :expressionless:

I tried to delete the domain, and re-add it in hopes to somehow dodge that quit scan, but there seems no way around this thing :frowning:

1 Like

Which domain is it? Did you possibly have a wildcard configured with your previous DNS service?

Does it list all these hosts after scanning or only once the domain is active in your dashboard?

You should probably contact support about that.

1 Like

Contact Support and ask them to wipe them all out. Then Import a BIND file with the ones you want.

Login to Cloudflare and then contact Cloudflare Support by clicking on the Get More Help button.

1 Like

I have the same problem. Just added 2 Domains and both got 1000 DNS entries added.
Ask the support to remove them all. Waiting for an answer.

1 Like

Due to their policy, they can’t make any changes to an account. Either way, I delete it by hand, or I build myself a script
https://api.cloudflare.com/#dns-records-for-a-zone-delete-dns-record

Great support :frowning:

That’s a bummer. Maybe now is the time for the Community to build up a library of handy API scripts for common routines. Something that loops through all records of a zone or account and apply the same operation to all of them.

2 Likes

I’d be mostly interested in why it happens. Unfortunately the OP didnt elaborate. My best guess still is a wildcard record.

2 Likes

Hmmm…I just tried importing one of my unused domains that had a wildcard subdomain, and Cloudflare figured out it’s a wildcard subdomain. :unamused:

No idea then :man_shrugging:t2:. Bug?

1 Like

No i had no wildcard running,ans asked my Provider, but they also habe no clue why that would happen :confused:

What did support say?

I do a lot of work in WordPress so it tends to be my “scripting” language. If this can help anyone else to just be able to copy and paste and run I will count it time well spent. it’s not pretty but it did delete 1000 records in just a couple minutes. Put this in the root of a WordPress install, replace <apikey>, <apiemail> and <zoneid> with the appropriate values and run the file as a PHP cli script.

$php script.php

<?php
/* script.php */
function auth_redirect(){};
function wp_get_current_user() {
    global $current_user;
    wp_set_current_user( 1 );
    get_currentuserinfo();
    return $current_user;
}

define( 'WP_USE_THEMES', false );
require_once( 'wp-load.php' );
require_once( 'wp-admin/includes/admin.php' );

global $wpdb;
set_time_limit( 0 );

$args = array(
    'method' => 'GET',
    'headers' => array(
        'X-Auth-Key' => '<apikey>',
        'X-Auth-Email' => '<apiemail>',
        'Content-Type' => 'application/json',
    ),
    'body' => ''
);
$url = 'https://api.cloudflare.com/client/v4/zones/<zoneid>/dns_records';
$response = wp_remote_request( $url, $args );

$res = json_decode($response['body']);
echo $res->result_info->total_count."\n";
do{
    foreach($res->result as $r){
        echo $r->id."\n";
        $args = array(
            'method' => 'DELETE',
            'headers' => array(
                'X-Auth-Key' => '<apikey>',
                'X-Auth-Email' => '<apiemail>',
                'Content-Type' => 'application/json',
            ),
            'body' => ''
        );
        $url = 'https://api.cloudflare.com/client/v4/zones/<zoneid>/dns_records/'.$r->id;
        $response = wp_remote_request( $url, $args );
    }

    $args = array(
        'method' => 'GET',
        'headers' => array(
            'X-Auth-Key' => '<apikey>',
            'X-Auth-Email' => '<apiemail>',
            'Content-Type' => 'application/json',
        ),
        'body' => ''
    );
    $url = 'https://api.cloudflare.com/client/v4/zones/<zoneid>/dns_records';
    $response = wp_remote_request( $url, $args );

    $res = json_decode($response['body']);
    echo $res->result_info->total_count."\n";

} while($res->result_info->total_count > 0)

?>

This topic was automatically closed after 31 days. New replies are no longer allowed.