Skip to main content

Identify orphaned DNS zones

Comments

7 comments

  • cPRex Jurassic Moderator

    Hey there!  If the server is part of a DNS cluster, you can use this command to look through the /etc/managedzones file on the machine and get such a list:

    for domains in $(ls /var/named/*.db | cut -d '/' -f 4 | awk 'BEGIN{FS=OFS="."}{NF--; print}' ); do if ! (grep -q $domains /etc/managed_domains);

    This is modified from our documentation here about cleaning up a bad cluster configuration:

    https://support.cpanel.net/hc/en-us/articles/4403207979159-Removing-unmanaged-zones-from-a-cluster-member

    Let me know if that works for your situation!

    0
  • ttremain

    Sorry, not my programming/scripting language.

    It acts as if I'm not complete or closing something, or mis-copy/pasted.  So I'm trying to break it down.

    This drops to the next command prompt as if not finished:  ">"

    This works fine and gives me a list of domains:

    ls /var/named/*.db | cut -d '/' -f 4 | awk 'BEGIN{FS=OFS="."}{NF--; print}'

    Is there supposed to be more after:

    .... do if ! (grep -q $domains /etc/managed_domains);
    0
  • ttremain

    I should add that I don't have a folder or file named /etc/managed_domains

    0
  • ttremain

    Here is what I came up with, after using yours as a jump off point:

     

    for domains in $(ls /var/named/*.db | cut -d '/' -f 4 | awk 'BEGIN{FS=OFS="."}{NF--; print}' ); do if ! (grep -q $domains /etc/userdomains ) then echo $domains;fi; done;

     

     

    1
  • docw

    This is slightly cleaner alternative:

    for domain in $(find /var/named/ -maxdepth 1 -type f -name "*.db" -exec basename \{} .db \;); do if ! grep -q "^$domain" /etc/userdomains; then echo "$domain"; fi; done;

    It uses `find` to return the list with ".db" files and to strip the ".db" extention (no need for awk).

     

    1
  • Mark Chapman

    Yes, this alternative worked for me, thanks for it. 

    0
  • cPRex Jurassic Moderator

    I'm glad you found a good solution!

    0

Please sign in to leave a comment.