This guide walks you through changing the primary IP address on a cPanel/WHM server. This is typically done when migrating to a new IP range or due to data center policy updates.
✅ Prerequisites
- Root SSH access to the server.
- Access to WHM (WebHost Manager).
- New IP address and gateway information from your hosting provider.
- Scheduled maintenance window.
🧭 Step 1: Update the Primary IP in WHM
- Log into WHM as
root. - Go to: WHM » Basic WebHost Manager Setup
- Find the option:
“The IP address (only one address) that will be used for setting up shared IP virtual hosts” - Update this IP to your new primary IP.
- Click Save at the bottom of the page.
⚠️ Note: This step doesn’t change the OS-level IP but is important for WHM/cPanel’s internal logic.
🔧 Step 2: Update Network Configuration via SSH
- SSH into your server as
root. - Edit the primary network interface file:
nano /etc/sysconfig/network-scripts/ifcfg-eth0Modify the following lines:IPADDR=NEW_PRIMARY_IP GATEWAY=NEW_GATEWAY_IPReplaceNEW_PRIMARY_IPandNEW_GATEWAY_IPwith your actual values. - Update
/etc/sysconfig/network(if the gateway is not specified in the interface file):nano /etc/sysconfig/networkAdd or modify:GATEWAY=NEW_GATEWAY_IP - Edit
/etc/ipsto manage additional IPs:- Remove the new primary IP if listed.
- Add the old primary IP as a secondary:
OLD_PRIMARY_IP ::
⚙️ Step 3: Update WHM and System Files
- Update
/var/cpanel/mainip:echo "NEW_PRIMARY_IP" > /var/cpanel/mainip - Edit
/etc/hosts:nano /etc/hostsReplace any instance of the old IP with the new IP, especially the line pointing to the server’s hostname. - Check DNS for your hostname (A record should match the new primary IP).
🔄 Step 4: Restart Network Services
- Restart the network interface:
systemctl restart network⚠️ This will disconnect your SSH session. Reconnect using the new IP address. - Restart IP aliasing (if used):
systemctl restart ipaliases - Verify IP addresses:
ip aEnsure the new primary and any secondary IPs are up.
🧪 Step 5: Verify cPanel License and WHM Functionality
- Verify WHM is accessible via the new IP:
- Open:
https://NEW_PRIMARY_IP:2087
- Open:
- Verify cPanel license: Run the command:
/usr/local/cpanel/cpkeycltOr check online:
👉 https://verify.cpanel.net - Confirm there are no license errors or warnings in WHM.
🧠 Final Notes
- Always make these changes during off-peak hours or a scheduled maintenance window.
- Keep your old IP functional for some time in
/etc/ipsto prevent sudden disruptions. - If hosted with a provider like OVH or Hetzner, ensure IP changes are reflected in the control panel or Netplan, if applicable.
