Remove DNS Zone Records via Command Line...

Hi Folks,

Does anyone know of a command line API call that can remove specific DNS zone records?

*** Before anyone suggests updating the DNS settings in the “Server Templates”, this option was already explored and currently is not suitable for my needs. ***

I want to delete a few DNS zone “records” upon post-creation of a “Top-Level” and “Sub-Level” domain.

Thanks in advance!

Check out the various options available in “virtualmin modify-dns”, I think you can do what you want with that.

-Eric

Eric,

I think that’ll work for this purpose.

One question though, after reviewing the options.

modify-dns.pl --domain mydomain.com --remove-record mydomain.com NS

Wouldn’t the above command remove “all” NS records for the domain? This seems a bit dangerous. What if someone wanted to remove just one NS record for example?

Well, you should probably test out the details here before making changes to a critical domain – but the help text reads:

–remove-record “name type”

So when you say “modify-dns.pl --domain mydomain.com --remove-record mydomain.com NS”, it should remove an “NS” record named “mydomain.com” – of which there could only ever be one in that zone.

-Eric

That’s not true.

Running with “mydomain.com NS” would “in theory” remove for example.

mydomain.com. NS ns1.mydns.com.


mydomain.com. NS ns2.mydns.com.


mydomain.com. NS ns3.mydns.com.

Those zone records are perfectly legal, as you are required to have more than one NS record per zone, all pointing to different DNS servers which manage your zone.

Anyhoo, I created a nicely little shell script which uses the “modify-dns.pl” command to iterate through a selected list of domains and remove the offending (as i like to put it) records. It’s been tested, and runs quite smoothly. Thankfully I don’t need to remove NS records for this case.

LoLz

Hrm, when I initially thought about the problem, I guess I figured it’d make more sense to refer to NS records by the right-hand side, which is typically something like ns1.domain.com.

But I guess for all other records, you’d use the left-hand side… so I dunno, I guess you’ll just have to experiment :slight_smile:

If you find yourself needing to remove NS records, and it doesn’t do what you need, feel free to file a Support request to get Jamie to take a look, maybe it should work differently.

-Eric

No worries, I’ve got things working as needed.

The next step is to expand my shell script so it deletes the rogue records based on a condition, and actually do it automatically upon post-creation of the domain (right now I simply created a batch shell script which calls my primary script which in turn removes the offending records from the selected domains)

Thanks for your assistance Eric!

Sorry for just needing to post here, but who in the heck is this Dissjrspc person?
If you folks take a look at this forum, it looks like spam to me.

Yeah, it was indeed spam… they had left a few messages around the forum, unfortunately :-/

I deleted all those posts last night, and banned the user though.

Thanks!

-Eric