How to change the primary IP addres of a Linux / cPanel server

How to change the primary IP addres of a Linux / cPanel server

Normally in all servers, the outbound connections from a server will be originating from the primary IP of the server. This is the case in a cPanel server as well. So if an IP is blacklisted, or blocked, some where we may need to change the primary IP address of the server.  If we are changing the network range this is needed.

I’d suggest to disable any firewall in the server before we start.

Step1. Login to the server via SSH , and open the file /etc/sysconfig/network-scripts/ifcfg-eth0, Change the IPADDR and GATEWAY entries to match the new IP and Gateway.

Step2. Then edit the file at /etc/sysconfig/network , if the GATEWAY entry is there, change it.

This much is needed in a normal CentOS server. You can now restart the network service and have the new IP in the server.  If you have cPanel installed, Please proceed further. cPanel have a few hardcoded locations where it save the IP address information, and they are…

  1. /var/cpanel/mainip.  Replace the old IP with the new one in this file.
  2. /etc/ips .  This file should not contain The main IP.
  3. /etc/hosts. Replace the old IP with the new one in this file.

Restart network and ipaliases service

service network restart
service ipaliases restart
Note: You're probably going to be disconnected at this point, and have to log in to ssh using the new primary ip, and restart the ipaliases service. 

Once you are up in the new IP, make sure that you have the cPanel license installed for the new IP and you might need to update the license using the command 


You will then need to login to WHM, and update the new IP in cPanel -> Basic Server settings, if you have the old IP listed there.

Again, if you are having a lot of websites running on that old IP you will need to change their IP from WHM -> Change Site’s IP address.

You will then need to update all your monitoring system to use the new IP – or else you’ll get those false alarms every now and then.

This Post Has One Comment

  1. This is also possible if they offer SEO as part of their service.

    Try your better to find the web hosting service without down time.
    The laws have been changing and many portals that offer services
    are finding it harder and harder to get their
    word out there.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close Menu