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!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SOLVED Bulk Change Records

Discussion in 'Bind / DNS / Nameserver Issues' 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:
    599
    Likes Received:
    92
    Trophy Points:
    153
    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
     
    #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:
    599
    Likes Received:
    92
    Trophy Points:
    153
    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
     
  6. Jcats

    Jcats Well-Known Member

    Joined:
    May 25, 2011
    Messages:
    599
    Likes Received:
    92
    Trophy Points:
    153
    Location:
    New Jersey
    cPanel Access Level:
    DataCenter Provider
    Beat me to it, glad its working :)
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,425
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    I'm happy to see the issue is now resolved. Thank you for updating us with the outcome.
     
Loading...

Share This Page