Disclaimer: We highly recommend consulting with your network or system administrator prior to making any changes, as failing to configure the interface correctly can result in an unreachable server. Ensure that you have console or other out-of-band access to the server before attempting to make any of these changes. cPanel Support is unable to assist with making any of these changes.
cPanel utilizes the IP address assigned to the network interface. cPanel has no supported way to do this in the WHM interface, so we strongly encourage you to reach out to your system administrator or network team to assist with making these changes. To change the primary IP, you must be familiar with a command-line text editor to update the system's network configuration file, cPanel's mainip file, rebuild NAT (Network Address Translation), and transfer your license.
First, log in to the WHM interface and navigate to Home » Server Configuration » Basic cPanel & WHM Setup. Change the main IP in the section The IP address (only one address) that will be used for setting up shared IP virtual hosts. This action updates
Next, via SSH change the IP in the network configuration file. You can see a configuration example from CentOS here: Network configuration files.
To change the IP, edit the
/etc/sysconfig/network-scripts/ifcfg-<interface_name> file, and replace the old IP with the new IP on the line that looks similar to IPADDR=192.xx.xx.xx and GATEWAY= with the new correct gateway. The file name is going to be ens# or eth#.
Once this is done, change the main IP in /var/cpanel/mainip by running the following script:
/scripts/mainipcheck. This action replaces the old IP with the new IP configured.
If the new IP was previously added to the server through Home » IP Functions » Add a new IP address, remove it from
/etc/ips or via the WHM interface at Home » IP Functions » Show or Delete Current IP Addresses.
You'll also need to fix the
/etc/hosts file for the new IP. This can be done with the fixetchosts script:
Next, restart the network service and rebuild NAT with the build_cpnat script for the changes to take effect. If the server is not using NAT, the build_cpnat script will exit cleanly:
service network restart && /scripts/build_cpnat > /dev/null 2>&1
You will likely get disconnected at this time and will need to log in again via the new IP address.
If the server has additional IP addresses, restart the ipaliases script to bring up the additional IPs:
service ipaliases restart
To verify the settings, run ifconfig to make sure everything shows up as expected, then update the cPanel license to the new primary IP and verify you can still log in to WHM without any warning.
This completes changing the primary IP address for your cPanel server. To find out how to bulk-change the IP address for your accounts, review How to change account IP addresses in bulk.