How to Change the Primary IP Address on a cPanel/WHM Server Print

  • cpanel
  • 3

This guide walks through how to change the primary IP address on a cPanel/WHM server running on CentOS 7, AlmaLinux 8/9, or Rocky Linux 8/9. Changing the primary IP requires updating the network interface configuration, several cPanel configuration files, the cPanel license, and DNS — in the correct order. Skipping or misordering steps will leave the server unreachable or cPanel unlicensed.

Need a dedicated server or VPS for cPanel hosting? Owned Networks provides dedicated servers and KVM VPS plans with full root access across US and EU locations. See our dedicated server plans and VPS locations.

Before You Start

  • Console or out-of-band access is mandatory. The server will be unreachable over SSH during the network restart. Have VNC, IPMI, or KVM console access open before you begin — you will need it to reconnect after the network change
  • Take a full snapshot or backup of the server before making any changes
  • Confirm the new IP address, subnet mask, and gateway with your hosting provider before editing any files
  • Identify your network interface name before starting — on modern systems it may be eth0, ens3, ens18, or another name. Confirm with ip addr or nmcli device status
  • Note the old primary IP — you will need it throughout this process
  • Plan for DNS propagation time after the IP change. Update DNS records for the server's hostname and all hosted domains pointing to the old IP before or immediately after the change

Overview of Files That Must Be Updated

  • Network interface config — assigns the new IP to the network interface
  • /var/cpanel/mainip — cPanel's record of the server's primary IP
  • /etc/wwwacct.conf — cPanel account creation defaults including the primary IP
  • /etc/ips — cPanel's list of additional IPs; the old primary may need to move here
  • /etc/hosts — hostname-to-IP mapping for the server itself
  • WHM Basic Setup — the shared IP setting in the WHM interface
  • cPanel license — must be updated to the new IP or WHM will show a license error

Step 1: Update WHM Basic Setup

Log into WHM and navigate to Home → Server Configuration → Basic cPanel & WHM Setup.

Find the field labeled "The IP address (only one address) that will be used for setting up shared IP virtual hosts" and change it to the new primary IP address. Save the changes.

This step updates the shared IP that WHM assigns to new hosting accounts. It can be done before or after the network change, but doing it first ensures cPanel's configuration is consistent before the network is modified.

Step 2: Update the Network Interface Configuration

The correct method depends on your Linux distribution.

CentOS 7 — Edit the ifcfg file

First confirm your interface name:

ip addr

Then edit the corresponding interface configuration file — replace eth0 with your actual interface name:

nano /etc/sysconfig/network-scripts/ifcfg-eth0

Update the IPADDR and GATEWAY lines to the new values:

IPADDR=new.primary.ip.address
GATEWAY=new.gateway.address

If GATEWAY is not in the ifcfg file, check /etc/sysconfig/network and update it there instead.

AlmaLinux 8/9, Rocky Linux 8/9 — Use nmcli

Replace eth0, the IP, prefix, and gateway with your actual values:

nmcli connection modify eth0 ipv4.addresses "new.primary.ip/prefix" ipv4.gateway "new.gateway"
nmcli connection modify eth0 ipv4.method manual

Step 3: Update cPanel Configuration Files

Before restarting the network, update all cPanel files that reference the old primary IP. Doing this before the network restart ensures cPanel comes up correctly on the new IP.

/var/cpanel/mainip

This file contains a single line — the server's primary IP. Replace it with the new IP:

echo "new.primary.ip.address" > /var/cpanel/mainip

/etc/wwwacct.conf

Find the ADDR line and update it to the new primary IP:

nano /etc/wwwacct.conf

Change the line:

ADDR new.primary.ip.address

/etc/ips

This file lists all additional IPs assigned to the server in the format IP:netmask:gateway. Make two changes:

  • If the new primary IP is listed here, remove it — the primary IP should not be in /etc/ips
  • If the old primary IP needs to remain on the server as a secondary IP, add it to this file in the correct format:
old.primary.ip.address:255.255.255.0:gateway.address

Adjust the netmask to match your actual subnet configuration.

/etc/hosts

Update the line mapping the server's hostname to its IP address:

nano /etc/hosts

Replace the old primary IP with the new one on the line containing the server's hostname. Example:

new.primary.ip.address  server.yourdomain.com  server

Step 4: Restart the Network

You will lose SSH connectivity at this point. Switch to your console or out-of-band access before running these commands.

CentOS 7

nmcli connection reload
nmcli connection up eth0

AlmaLinux 8/9, Rocky Linux 8/9

nmcli connection reload
nmcli connection up eth0

After the network restarts, reconnect to the server using the new primary IP address via SSH.

Step 5: Verify the Network Change

After reconnecting, confirm the new IP is active and all IPs are showing correctly:

ip addr

The new primary IP should appear on the main interface. If the old primary IP was retained as a secondary, confirm it also appears. If any IPs are missing, check /etc/ips and restart the cPanel ipaliases service:

systemctl restart cpanel

Step 6: Update the cPanel License

cPanel licenses are tied to the server's primary IP. After changing the IP, the license must be updated or WHM will display a license error. Run the cPanel license update script:

/usr/local/cpanel/cpkeyclt

This contacts the cPanel licensing server and updates the license to the new primary IP. If your license is managed through a reseller or hosting provider rather than directly through cPanel, contact them to update the IP associated with your license.

Step 7: Restart cPanel Services

Restart cPanel to ensure all services pick up the new IP configuration:

systemctl restart cpanel

Or use the cPanel restart script:

/scripts/restartsrv_cpsrvd

Step 8: Verify WHM Access and License

Log into WHM using the new primary IP:

https://new.primary.ip.address:2087

Confirm there are no license warnings on the WHM dashboard. You can also verify the license status directly at:

https://verify.cpanel.net/

Post-Change Checklist

  • DNS records: Update the A record for the server's hostname and any domains pointing to the old primary IP. DNS propagation can take up to 48 hours depending on TTL settings
  • SSL/TLS certificates: If any certificates are bound to the old IP or issued to the server's hostname, reissue or update them. cPanel's AutoSSL can reissue certificates automatically once DNS propagates
  • cPanel account IPs: In WHM, go to IP Functions → Show IP Address Usage to confirm accounts are assigned to the correct IPs
  • Firewall rules: If the server uses CSF, iptables, or another firewall, update any rules that reference the old primary IP specifically
  • Remote monitoring: Update any external monitoring tools that check the server by IP

Related Solution

Need a dedicated server or VPS for cPanel hosting?

Owned Networks provides dedicated servers and KVM VPS plans with full root access, static IP addresses, and support for cPanel/WHM installations. Deploy in US and EU locations with your choice of AlmaLinux, Rocky Linux, or CentOS.

  • Deploy in NYC, Miami, Dallas, LA, Seattle, London, or Amsterdam
  • AlmaLinux, Rocky Linux, CentOS available for cPanel compatibility
  • Static IPs, full root access, and out-of-band console included

View Dedicated Server Plans

Frequently Asked Questions

Will changing the primary IP break hosted websites?

Temporarily, yes. Websites on shared hosting accounts use the server's primary IP by default. Once the IP changes and DNS records are updated, traffic will resolve to the new IP and sites will come back online. The downtime window is typically the length of the DNS TTL for each domain. Domains with dedicated IPs assigned through WHM will need those IP assignments reviewed separately.

Do I need to update DNS before or after changing the IP?

Update DNS before or simultaneously with the IP change if possible. Lowering the TTL on affected DNS records 24–48 hours before the change reduces propagation time. If you update DNS after, expect an outage window equal to the current TTL of the affected records.

What if WHM shows a license error after the IP change?

Run /usr/local/cpanel/cpkeyclt to force a license refresh. If the error persists, the license in your cPanel store or reseller account may still be registered to the old IP. Log into manage2.cpanel.net and update the IP associated with the license, then run the refresh script again.

What is /etc/ips and why does the old primary IP need to go there?

The /etc/ips file lists all secondary IP addresses that cPanel's ipaliases service brings up at boot. The primary IP is managed by the network interface configuration and should not be in this file. If the old primary IP needs to remain on the server — for example, if hosted accounts or SSL certificates were tied to it — it must be added to /etc/ips so cPanel continues to manage it as a secondary IP.

Why use nmcli instead of restarting the network service?

The network service (service network restart) was removed in RHEL 8 and all compatible distributions including AlmaLinux 8/9 and Rocky Linux 8/9. It no longer exists on these systems. The nmcli connection reload method works on all supported distributions — CentOS 7, AlmaLinux 8/9, and Rocky Linux 8/9 — and is the correct modern approach.

Should I use ifconfig or ip addr to verify the IP change?

Use ip addr. The ifconfig command is part of the deprecated net-tools package and is not installed by default on modern Linux distributions. The ip command from the iproute2 package is the current standard and is available on all distributions covered in this guide.


Was this answer helpful?

KVM VPS & Dedicated Servers

Deploy a Linux VPS in under 2 minutes — AlmaLinux, Rocky Linux, Ubuntu, Debian. Full root access, KVM virtualization, US and EU locations.

« Back