There may come a point in time where you need to change the shared IP address of a server, with little to no interruption in service for your users.
This guide will show you how to change the shared IP of your cPanel server with the method I’ve used in the past. This is intended for intermediate to advanced administrators that have some basic knowledge of cPanel and networking. This will only update the main IP of your server, and will not affect accounts that have dedicated IPs or SSL certificates.
Update your TTLs
The first thing you need to set your zone TTL’s on the server to a lower value a day or two prior to changing the IP, so the caching period is lower. Caching DNS servers should be configured to use the TTL value, and while all may not be configured to work this way, you should prevent inconvenience to most of your users by configuring the value as low as possible – usually to 3200.
There may be some methodical science behind this that you can come up with, but I found that the easiest way to do change the TTL’s for everyone on one server is with a simple replace:
replace 86400 3200 — /var/named/*.db
You can change the first value to whatever you have your default TTL set to, which is indicated in /etc/wwwacct.conf. After this, use the following script to increment up the serial numbers:
Now sync the zones out to the cluster to update your nameservers:
/scripts/dnscluster synczone all
Add the new IP
A couple days after you make this change, add the new IP to your server. You can edit /etc/wwwacct.conf to indicate the interface and IP that should be shared, but I find that having the main IP also be the shared IP works best. The reason for this is that if you, for example, have the eth0:1 interface as the shared IP, each IP added after that as an alias will have an interface of eth0:1:x and won’t work properly.
To change the main IP of the server:
- Edit /etc/sysconfig/network-scripts/ifcfg-ethx (ethx = adapter your public IP is on)
- Modify IPADDR, NETMASK, GATEWAY and NETWORK to match your IP parameters (some may not be present)
- Edit /etc/sysconfig/network to change additional parameters not preset in the previous file
- Restart the network service
NOTE: This example refers to a Redhat-type system. Actual file names you need to edit would differ depending on what flavor of Linux you’re on.
Now, all you need to do is run a few more replace commands:
- replace $oldip $newip — /var/cpanel/mainip
- replace $oldip $newip — /var/cpanel/userdata/*/*
- replace $oldip $newip — /var/named/*.db
- replace $oldip $newip — /etc/*
- service named restart
You also need to run the same script as before to update the zone serials again (now that they have new IPs) and sync the domains back up to the clusters. Then use the same replace command (only opposite) to change the TTL’s back to the original values.
To complete the change, I would advise running a cPanel update in case any internal cPanel files are using the previous IP.