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-eth0
Modify the following lines:IPADDR=NEW_PRIMARY_IP GATEWAY=NEW_GATEWAY_IP
ReplaceNEW_PRIMARY_IP
andNEW_GATEWAY_IP
with your actual values. - Update
/etc/sysconfig/network
(if the gateway is not specified in the interface file):nano /etc/sysconfig/network
Add or modify:GATEWAY=NEW_GATEWAY_IP
- Edit
/etc/ips
to 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/hosts
Replace 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 a
Ensure 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/cpkeyclt
Or 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/ips
to 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.