Skip to main content

How to remove DNS Zone via SSH if its Domain doesn't exist?

Comments

16 comments

  • techAMIGO
    Hi, Do not manually remove the zone file from /var/named .. the zone file entry is also in /etc/named.conf even if the domain is not existing, you can remove the zone from WHM Home >>> DNS Functions >>> Delete a DNS Zone. zone will be listed there and you can delete from there.
    0
  • ImperialTrader
    Hi, Do not manually remove the zone file from /var/named .. the zone file entry is also in /etc/named.conf even if the domain is not existing, you can remove the zone from WHM Home >>> DNS Functions >>> Delete a DNS Zone. zone will be listed there and you can delete from there.

    I can't remove it from WHM, because I'm using DNS Cluster and the file will be deleted from the DNSOnly server. I need to remove the DNS file using SSH
    0
  • techAMIGO
    I'm not sure why you need to delete it from server only.. since you mention you're using a DNS cluster that means. zone not related to the server also seeing in the /var/named directory. it is because you have set the DNS cluster mode as synchronize. so you can change to cluster mode to standalone mode to avoid that. also in standalone mode if you make any changes it will not reflect to other servers. if you need to remove them manually then you need to perform two actions, 1) remove the entries from /etc/named.conf .. entries will be like zone "domain_name.com" { type master; file "/var/named/domain_name.com.db"; }; 2) then delete the zone file from /var/named/domain_name.com.db which I don't recommend doing manually via SSH. instead please try standalone mode for DNS cluster
    0
  • ImperialTrader
    I'm not sure why you need to delete it from server only.. since you mention you're using a DNS cluster that means. zone not related to the server also seeing in the /var/named directory. it is because you have set the DNS cluster mode as synchronize. so you can change to cluster mode to standalone mode to avoid that. also in standalone mode if you make any changes it will not reflect to other servers. which I don't recommend doing manually via SSH. instead please try standalone mode for DNS cluster

    I know that the DNS zones aren't related to the server, I just need to clean each server from the extra/unused zones after I move the website from one server to another. Also, I don't want to manually remove the zone via SSH, I need this script to run automatically every day via cron job.
    0
  • ImperialTrader
    Any updates? :)
    0
  • cPRex Jurassic Moderator
    As mentioned above, there aren't going to be any automated tools to perform this work. I'm still a bit confused about your cluster configuration and why it would be leaving DNS zones on a server - once the account is terminated on the Source machine after the migration is complete, the zone would also be removed.
    0
  • ImperialTrader
    As mentioned above, there aren't going to be any automated tools to perform this work. I'm still a bit confused about your cluster configuration and why it would be leaving DNS zones on a server - once the account is terminated on the Source machine after the migration is complete, the zone would also be removed.

    That's correct, but my issue is not in the termination of the account. My issue, that I always move the account from one server to another, after this move, the DNS zone will exist on both servers, I just want to remove it from the old server only using an automated tool or script
    0
  • cPRex Jurassic Moderator
    You could use the "/scripts/killdns" tool to help automate this process.
    0
  • InterServed
    Hi there, I believe that what you are looking for can be found on this thread:
    0
  • ImperialTrader
    Hi there, I believe that what you are looking for can be found on this thread:
    0
  • cPRex Jurassic Moderator
    In general, I don't like to see a separate zone file for the hostname, so it's unlikely you need to recreate that. Usually that data is served elsewhere, as the host A recornd and NS/A records for the nameservers are handled in the main domain.com zone file.
    0
  • ImperialTrader
    In general, I don't like to see a separate zone file for the hostname, so it's unlikely you need to recreate that. Usually that data is served elsewhere, as the host A recornd and NS/A records for the nameservers are handled in the main domain.com zone file.

    Ok, that's fine then I don't need to re-create them again! When I run this script command /scripts/unmanaged_zones
    it asks me for confirmation [y/n] how to make it (y) in the command?
    0
  • cPRex Jurassic Moderator
    While the command doesn't have any flags that support that, you could likely use the Linux command "yes" to help automate that process. That would look something like this: yes | /scripts/unmanaged_zones
    which answers "y" to all questions.
    0
  • ImperialTrader
    While the command doesn't have any flags that support that, you could likely use the Linux command "yes" to help automate that process. That would look something like this: yes | /scripts/unmanaged_zones
    which answers "y" to all questions.

    hmm, doesn't work!
    0
  • cPRex Jurassic Moderator
    That's odd - if "yes" can't be applied to that, I don't have any other automated options that I can think of.
    0
  • InterServed
    Hi, Please make backup before trying this method. Executing this will auto answer with y. 1. Create a new file, example expectscript.exp (requires expect package to be installed) 2. The content of the file/script: #!/usr/bin/expect -f set force_conservative 0 ;# set to 1 to force conservative mode even if ;# script wasn't run conservatively originally if {$force_conservative} { set send_slow {1 .1} proc send {ignore arg} { sleep .1 exp_send -s -- $arg } } set timeout -1 spawn /scripts/unmanaged_zones expect -exact "Would you like to remove the zone files and entries in /etc/named.conf for the unauthoritative zones on this server only? (y/n) " send -- "y\r" expect eof
    3. chmod +x expectscript.exp 4. The execute the script: ./expectscript.exp Hopefully this will do the tasks you desire, and don't forget to always make a backup of /etc/named.conf and /var/named.
    0

Please sign in to leave a comment.