Skip to main content

Best method to remove from domain zone

Comments

5 comments

  • cPRex Jurassic Moderator
    Hey there! While this is definitely doable, I'm extremely hesitant to post any one-liners on the Forum for all to see. One typo and then we get the blame for destroying someone's DNS :D A combination of "find" along with a "$ sed -i '/string/d' myfile.txt" would delete the entire line containing the matching output.
    0
  • Steini Petur
    Hey there! While this is definitely doable, I'm extremely hesitant to post any one-liners on the Forum for all to see. One typo and then we get the blame for destroying someone's DNS :D A combination of "find" along with a "$ sed -i '/string/d' myfile.txt" would delete the entire line containing the matching output.

    Haha, I know @cPRex but any one liners you would do, I would most likely run dry-run, by doing "echo" on it or print it.. I tried the sed and I have done SED in the past using # Replace temporarily all versions with no disable_functions sed -i 's/disable_functions = .*/disable_functions = /' /opt/cpanel/ea-php56/root/etc/php.ini
    When I needed to remove all content in the disable_functions before running pecl installer, then add again my disable_functions. However something about the large space, is giving me issues, but Ill try, Ill create a fake file to attempt to do this, see if I can somehow take everything between "IN(space)" Could have been just not my day yesterday, one of those days when nothing works, maybe today is different :P
    0
  • Steini Petur
    It was just one of those days, this was enough to get it done sed -i '/IN.*NS.*ns[0-9].*/d' testdomain.is.db.2
    cat testdomain.is.db.2 | grep SOA testdomain.is. 86400 IN SOA ns3.y.com sed -i 's/SOA.*ns[0-9].*/SOA siti.ns.y.com reports.y.com (/' testdomain.is.db.2 cat testdomain.is.db.2 | grep SOA testdomain.is. 86400 IN SOA siti.ns.y.com reports.y.com (
    Knowing this, I can then iterate throughit with a for loop, this gets me where I need to go, thanks for the confirmation that my SED was in the right direction, the only problem I wasn't sure was how to match all the empty space, seems ".*" does it, although looking at it it feels wrong, feels like the regex should be something else.. Im getting off easy.. This will help me get rid of lines which have "ns1 ns5 ns10" while retaining the Cloudflare type of naming "john.ns.domain.tld" :)
    0
  • cPRex Jurassic Moderator
    There you go, and thanks for sharing!
    0
  • Steini Petur
    Note: My SED is not 100%, its reliant on the structure of your zone to be exactly SOA .... ( and a linebreak with all the retry, mname etc... below, some of our zones had all the content for odd reasons in one line off-screen behind a $ in the terminal, so I wiped out the SOA for like 90 of 2k domains, but managed to locate any entry without ";retry" with grep to make a list and fix those, here is how I did it :) The way I fixed it is 1. Make sure you dont delete your named.bak file of course. 2. I did a "grep -L ";retry" *.db | sed s/".db"// > /broken" inside the /var/named.bak this listed all files that do not have ;retry comment in them for some reason, and separate apart from the normal design 3. now that I have the /broken file 4. I replaced them again for i in $(cat /broken); do echo yes | cp -avr /var/named.bak/$i.db /var/named/ done
    5. Now I got them back in place, It's time to update the SOA of those weird files properly. for i in $(cat /broken); do sed -i 's/SOA.*ns[0-9].*/SOA siti.ns.y.com. reports.y.com. 2023021501 3600 1800 1209600 86400/' /var/named/$i.db done
    Im well aware that, it creates the same Serial on every zone, what I do now just updates those zones like before but instead of my full domainlist its just those broken, and dont mind the one liner SOA, it's recognized by WHM as a healthy record and intodns.com agrees. for i in $(cat /broken); do whmapi1 addzonerecord domain=$i name=dummy123.$i. class=IN ttl=14400 type=TXT txtdata="dummy" done
    followed by removing the dummy record of course for x in $(cat /broken); do for i in $(cat /var/named/$x.db | wc -l) do whmapi1 removezonerecord zone=$x line=$(($i - 1)) done done
    And now I got em all perfect, with updated SOA serial because whmapi1 add and remove record will update it for me.
    0

Please sign in to leave a comment.