๐Ÿ› ๏ธ Guide to Changing the Primary IP in WHM (cPanel)

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

  1. Log into WHM as root.
  2. Go to: WHM ยป Basic WebHost Manager Setup
  3. Find the option:
    โ€œThe IP address (only one address) that will be used for setting up shared IP virtual hostsโ€
  4. Update this IP to your new primary IP.
  5. 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

  1. SSH into your server as root.
  2. 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 Replace NEW_PRIMARY_IP and NEW_GATEWAY_IP with your actual values.
  3. 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
  4. 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

  1. Update /var/cpanel/mainip: echo "NEW_PRIMARY_IP" > /var/cpanel/mainip
  2. 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.
  3. Check DNS for your hostname (A record should match the new primary IP).

๐Ÿ”„ Step 4: Restart Network Services

  1. Restart the network interface: systemctl restart network โš ๏ธ This will disconnect your SSH session. Reconnect using the new IP address.
  2. Restart IP aliasing (if used): systemctl restart ipaliases
  3. Verify IP addresses: ip a Ensure the new primary and any secondary IPs are up.

๐Ÿงช Step 5: Verify cPanel License and WHM Functionality

  1. Verify WHM is accessible via the new IP:
    • Open: https://NEW_PRIMARY_IP:2087
  2. Verify cPanel license: Run the command: /usr/local/cpanel/cpkeyclt Or check online:
    ๐Ÿ‘‰ https://verify.cpanel.net
  3. 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.
Scroll to Top