Bobcares

How to Change Primary IP in cPanel Server

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.

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.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

GET UP TO 25% OFF

cPanel Support

Spend time on your business, not on your servers.

Managing a server is time consuming. Whether you are an expert or a newbie, that is time you could use to focus on your product or service. Leave your server management & end-user tech support to us, and use that time to focus on the growth and success of your business.

TALK TO US Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF