Learn how to change the primary IP in the cPanel server. Our cPanel Support team is here to assist you with any questions or concerns you may have.

How to Change Primary IP in cPanel Server

How to Change Primary IP in cPanel ServerIf you are preparing to change the primary IP address of a server running cPanel/WHM, here are some helpful guidelines from our Experts.

An incorrect configuration can render the server inaccessible. Therefore, we need to coordinate with the network or system administrator. cPanel does not support direct changes to the primary IP address via its interface. Thus, this guide will walk you through the steps required to perform the update safely using both the WHM interface and the command line.

Please note that if the interface is not configured correctly, the server may become unreachable.

An Overview:

Prerequisites

Here are a few things we need to be aware of before we begin:

  • SSH to edit system configuration files.
  • The changes involve updating the network configuration, cPanel’s internal IP references, and possibly adjusting NAT settings.
  • We will temporarily lose SSH connectivity once the IP address is changed, and we will need to reconnect using the new IP address.

If you’re making other major changes to your cPanel setup, such as switching domains, check out how to change the primary domain in cPanel.

How to Change Primary IP

Method 1. Via WHM and Command Line

  1. First, log in to WHM and head to Home > Server Configuration > Basic cPanel & WHM Setup.
  2. Remember to note down the current settings before making any changes.
  3. Then, SSH into the server and edit the network interface configuration file:
    vi /etc/sysconfig/network-scripts/ifcfg-eth0/
  4. Now, update the `IPADDR` and `GATEWAY` values with the new IP details.
  5. Next, update the main cPanel IP File:
    echo "NEW_IP_ADDRESS" > /var/cpanel/mainip
  6. We need to remove old and duplicate IPs. If the new IP was previously added to the server, remove it from `/etc/ips` or go to WHM > IP Functions > Display or Remove Current IP Addresses.
  7. Now, update the `/etc/hosts` File:
    /scripts/fixetchosts
  8. Then, apply restart network services and rebuild NAT:
    service network restart && /scripts/build_cpnat > /dev/null 2>&1

    We will be disconnected at this point. Now, log back in using the new IP address.

  9. Next, restart the IP aliases script:
    service ipaliases restart
  10. Finally, verify the configuration by running:
    ifconfig

    Check that the new IP is active and properly configured.

  11. We can update the cPanel license by heading to this link. Ensure the license is now associated with the new primary IP address.

Method 2. Alternate Steps via WHM and SSH

Here is an alternate method:

  1. Go to WHM > Server Configuration > Basic cPanel & WHM Setup.
  2. Then, change the value under:
    • The IP address (only one address) that will be used for setting up shared IP virtual hosts

    This step may be optional, depending on the setup.

    Looking to update other server settings too? Learn how to change the root directory in cPanel to point to a custom folder.

  3. Now, get ready to edit `/etc/sysconfig/network-scripts/ifcfg-eth0` and update `IPADDR` and `GATEWAY`.
  4. Also, edit `/etc/sysconfig/network` if necessary. Ensure the correct `GATEWAY` is set.
  5. Furthermore, update the following files:
    • /etc/ips: Remove new IP if it’s already listed.
    • /var/cpanel/mainip: Replace old IP with the new one.
    • /etc/hosts: Update IP reference for your hostname.
  6. Then, it is time to restart network services:
    service network restart
  7. Next, restart IP aliases:
    service ipaliases restart
  8. Run `ifconfig` to verify IP status and update the cPanel license.

Final Checks and Recommendations

  • Ensure WHM is accessible via `https://:2087`.
  • Verify there are no license errors after logging into WHM.
  • Remove the old IP via WHM by going to Home > IP Functions > Show or Delete Current IP Addresses. Additionally, add new IP addresses as needed under Home > IP Functions > Add a New IP Address.

If you’re using a temporary IP for testing before DNS propagation, here’s how to use a cPanel temporary URL to preview your website.

Bonus Tip: Planning to build out more functionality under your new IP setup? You might also be interested in learning how to create subdomains in cPanel using PHP, which can help automate parts of your hosting operations.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Changing the main IP address on a cPanel/WHM server requires caution. So, always back up configurations before making changes.

In brief, our Support Experts demonstrated how to change the primary IP in the cPanel server.

Similar Posts