Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

SOLVED Bulk Change Records

Discussion in 'Bind/DNS/Nameserver' started by zohair28, Mar 2, 2017.

  1. zohair28

    zohair28 Member

    Joined:
    Jan 26, 2010
    Messages:
    13
    Likes Received:
    1
    Trophy Points:
    53
    Hi,

    I'm trying to make a change inside all DNS zones, The mail record is "mail.domain.com" And I want to change to be "mail.dnszonename.com"

    Where dnszonename is true domain name for each domain on server.

    I wrote this command:-

    for i in `cat /etc/trueuserdomains | cut -d: -f1`; do replace "admin.domain.com" "admin.$i" -- $i.db; done;

    But when I ran this, Records changed to be first domain records in "/etc/trueuserdomains"

    Could anyone help me to get the correct command to change this record for all DNS zones?

    Regards


    Zoahir
     
  2. Jcats

    Jcats Well-Known Member

    Joined:
    May 25, 2011
    Messages:
    720
    Likes Received:
    123
    Trophy Points:
    168
    Location:
    New Jersey
    cPanel Access Level:
    DataCenter Provider
    This should work:

    Code:
    # for i in $(ls *.db | sed 's/.db//g') ; do sed -i.bak "s/admin.domain.com/admin.$i/g" $i.db ; done
    but first

    Code:
    # cp -rf /var/named /var/named.bk
    sed will create a backup of each zone as well but much easier to revert by just replacing the entire folder from the above backup.

    You also have to increment the serial in each DNS zone by 1.

    Code:
    # find /var/named/*.db -mtime -1 -exec perl -pi -e 'if (/^\s+(\d{10})\s+;\s+serial/i) { my $i = $1+1; s/$1/$i/;}' '{}' \;
    
    I haven't tested the above so I would try it out on one zone just too make sure it works then

    Code:
    # service named reload
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #2 Jcats, Mar 2, 2017
    Last edited: Mar 2, 2017
  3. zohair28

    zohair28 Member

    Joined:
    Jan 26, 2010
    Messages:
    13
    Likes Received:
    1
    Trophy Points:
    53
    Many thx for your answer but I got this inside mail value after running command:-

    admin.$i.

    So still this is not the correct value, What do you think?
     
  4. zohair28

    zohair28 Member

    Joined:
    Jan 26, 2010
    Messages:
    13
    Likes Received:
    1
    Trophy Points:
    53
    It is working now! I changed ' with " for sed command.

    for i in $(ls *.db | sed 's/.db//g') ; do sed -i.bak "s/admin.domain.com/admin.$i/g" $i.db ; done

    Many thx again!!
     
    Jcats likes this.
  5. Jcats

    Jcats Well-Known Member

    Joined:
    May 25, 2011
    Messages:
    720
    Likes Received:
    123
    Trophy Points:
    168
    Location:
    New Jersey
    cPanel Access Level:
    DataCenter Provider
    Sorry please use:

    Code:
    # for i in $(ls *.db | sed 's/.db//g') ; do sed -i.bak "s/admin.domain.com/admin.$i/g" $i.db ; done
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Jcats

    Jcats Well-Known Member

    Joined:
    May 25, 2011
    Messages:
    720
    Likes Received:
    123
    Trophy Points:
    168
    Location:
    New Jersey
    cPanel Access Level:
    DataCenter Provider
    Beat me to it, glad its working :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,233
    Likes Received:
    1,939
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    I'm happy to see the issue is now resolved. Thank you for updating us with the outcome.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice