rezman

Well-Known Member
Feb 3, 2011
45
0
56
USA
cPanel Access Level
Root Administrator
Continued from: http://forums.cpanel.net/f5/bulk-edit-dns-zones-211731.html

Hello :)

The replace command can be useful, but please note you will need to manually update the serials in the zones afterward. The "IP Migration Wizard" will complete this for you automatically.

Thank you.
We're setting up new CP DNS only servers and I need to update all the DNS zones and remove the old DNS server and replace it with the new host address.

Current:
Code:
;; AUTHORITY SECTION:
domain.com.             86400   IN      NS      [COLOR="#FF0000"]cpanel1.company.net[/COLOR].
domain.com.             86400   IN      NS      cpanel2.company.net.
New:
Code:
;; AUTHORITY SECTION:
domain.com.             86400   IN      NS      [COLOR="#FF0000"]cpdns1.company.net[/COLOR].
domain.com.             86400   IN      NS      cpanel2.company.net.
The command line "replace" would work perfect for this but is there a way to do it via WHM? I've already updated the nameservers under WHM > Basic cPanel & WHM Setup > Nameservers but it won't update the NS entry in all the zone files. I did the "replace" method on my personal domain, restarted named and did a dig @cpanel2.company.net mydomain.com and everything came back correct with the new AUTHORITY SECTION: DNS servers.
 

stdout

Well-Known Member
Apr 10, 2003
189
7
168
Nelspruit, Mpumalanga, South Africa
cPanel Access Level
Root Administrator
I don't know of any way to do it using WHM.
Why don't you just use replace?

1. Back up ALL DNS Zonefiles.
Code:
cp -rpf /var/named /var/named.backup
2. Update the Nameserver's in ALL DNS Zonefiles:
Code:
replace "cpanel1.company.net" "cpdns1.company.net" -- /var/named/*.db
3. Update the Serial/Timestamp in ALL DNS Zonefiles:
Code:
grep "serial, todays" /var/named/*.db | sed "s/://g" | cut -d/ -f4 | awk {'system("replace "$2" "strftime("%Y%m%d")"00 -- /var/named/"$1)'}
 

robb3369

Well-Known Member
Mar 1, 2008
122
1
66
cPanel Access Level
Root Administrator
Why don't you just add the new DNS server, sync it up and change the IP address of cpanel1.company.net in both your DNS and the registrar of your domain to the new IP address.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello :)

It's not possible to make this modification via Web Host Manager. You could use the "replace" command as mentioned, and then update the serials with the following commands:

Code:
# cp -a /var/named /var/named-backup 
# 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/;}' '{}' \;
Thank you.
 

rezman

Well-Known Member
Feb 3, 2011
45
0
56
USA
cPanel Access Level
Root Administrator
@stdout & cPanelMichael

Thank you all for the info. Using the 'replace' was my fallback option but I wanted to make sure there wasn't some hidden way within WHM first. Also I didn't know an easy way to update the serial numbers off hand. Thank you for these twp examples.


@robb3369:

That's an option for now and I will be doing that as a temporary solution but at some point we want to bring the cpanel1 server back online and use it as a full Cpanel server. Right now it is but only acting as a secondary DNS server. Need to bring it offline for now which is why I'm setting up DNS only servers so if this happens in the future I won't need to deal with updating domain name servers (again).
 

cglmicro

Member
Oct 14, 2013
11
1
53
cPanel Access Level
Root Administrator
3. Update the Serial/Timestamp in ALL DNS Zonefiles:
Code:
grep "serial, todays" /var/named/*.db | sed "s/://g" | cut -d/ -f4 | awk {'system("replace "$2" "strftime("%Y%m%d")"00 -- /var/named/"$1)'}
In my case, I also had to run this since many domains have different phrasing :
Code:
grep "Serial Number" /var/named/*.db | sed "s/://g" | cut -d/ -f4 | awk {'system("replace "$2" "strftime("%Y%m%d")"00 -- /var/named/"$1)'}
Another question: my files contain the priority that need to be changed from 21 to 10. I don't want to run:
Code:
replace "21" "10" -- /var/named/*.db
because it will change some things like IP 69.70.71.21 to 69.70.71.10.

QUESTION #1: What would be the command to only change:
Code:
replace "{TAB}21{TAB}" "{TAB}10{TAB}" -- /var/named/*.db
QUESTION #2: On my secondary NS that run under WHM_DNSONLY, should I force a full synchronisation, or should I wait for it to be done automaticaly?

Thanks!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
QUESTION #2: On my secondary NS that run under WHM_DNSONLY, should I force a full synchronisation, or should I wait for it to be done automaticaly?
You can manually synchronize the zones after updating the serials.

Thank you.