How to fix local IP in Nat Configuration on WHM/Cpanel on Centos 6 on Google Compute Engine

11,677

Solution 1

Its a configuration issue within WHM/Cpanel that can not be corrected with any configuration settings in the interfaces. I contacted Cpanel Support and they provided me with a command line shell script to run from root to fix the issue. It worked flawlessly:

# /scripts/build_cpnat

This resolved the issue, but they gave this additional info if that does not solve your problem:

If this does not resolve your issue, please review our NAT documentation and ensure that your server is configured in a supported 1:1 NAT configuration: http://documentation.cpanel.net/display/ALD/1%3A1+NAT

Solution 2

The Compute Engine does not allow you to create an instance with a specific network IP address. You will have to use a combination of routes and an instance's --can-ip-forward ability to add an IP address as a static network IP address that then maps to your desired virtual machine instance.

For example, if you want to assign 10.1.1.1 specifically as a network IP address to a virtual machine instance, you can create a static route that sends traffic from 10.1.1.1 to your instance, even if the instance's network IP address assigned by Compute Engine doesn't match your desired network IP address.

Take a look at this link: https://cloud.google.com/compute/docs/instances-and-network#staticnetworkaddress

Solution 3

I had the same issue with AWS and CentOS 7 hosting latest WHM/ cPanel. each time the instance restarts then a new private/ local IP address. I deleted cpnat from /var/cpanel/.

So I disabled the NAT, then I created another eth so I can configure it with static IP which is the Public IP, then for the main account only which own the hostname and domain name for WHM I assigned it to the local IP address, but as the local IP address keep changing so I created a script fires up at the start after each boot collecting the new local IP address and assign it automatically to the main account and if there is no new local IP address then the script exit without doing anything.

here are the steps been done:

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

and inside that file put the following: (change IPADDR & DNS)

DEVICE="eth0:cp1"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="13.54.100.XX"
NETMASK="255.255.255.0"
DNS1="172.31.0.2"
TYPE="Ethernet"
IPV6INIT="no"

now we would like this interface to stay upon reboot and start on the reboot so run:

ifup eth0:cp1

then restart the network service by: service network restart

now disable NAT mode by deleting the file cpnat in /var/cpanel

now check the file /var/cpanel/mainip and make sure our external ip is there 13.54.100.XX create the following file with nano:

nano /etc/init.d/fixdhcp

add the following to the file and save it:

#!/bin/bash
# # This script assigns available DHCP IP to ACCOUNT-NAME user on Reboot or Restart, please change ACCOUNT-NAME to the main WHM domain account name
# apache service will restart when done.    

/scripts/rebuildippool
export mydhcp10=$(cat /etc/ipaddrpool)
echo $mydhcp10

# Exit if no available IPs
if [ "${mydhcp10}" == "" ]; then
echo "ipaddrpool is empty" && exit 1
else
echo "ipaddrpool is not empty"
fi

/usr/local/cpanel/bin/setsiteip -u ACCOUNT-NAME $mydhcp10
chmod +x /etc/rc.d/rc.local
echo finished now restarting services
/scripts/rebuildhttpdconf
/scripts/rebuildippool
/scripts/cleandns
/scripts/fixvaliases
/scripts/modify_accounts --theme=paper_lantern --all-users
/usr/local/cpanel/scripts/updateuserdomains
service httpd restart

make the file excutable:

chmod +x /etc/init.d/fixdhcp

add it to rc.d

nano /etc/rc.local

then add it like this:

/etc/init.d/fixdhcp

save then run:

chmod +x /etc/rc.d/rc.local

Solution 4

The best and the simplest solution for this is to use the WHM/Cpanel IP Migration Wizard option to change the existing Private IP with the new one and then wait for few hours to make those changes propagate and you will see the new Private IP and Public IP in sync in your WHM platform.

WHM IP Migration Wizard Page

Share:
11,677
Michael Falciglia
Author by

Michael Falciglia

Updated on June 05, 2022

Comments

  • Michael Falciglia
    Michael Falciglia over 1 year

    If you deleted a VM on Google Compute Engine on a Centos 6 Cpanel server and then create it with the same disk, you often are assigned a new local IP address even if you kept the static IP. This does not properly update in the NAT configuration on Cpanel/WHM servers.

    This stops any sites from working and the only way to fix it is manually edit the http.conf file. Inside Web Host Manager you can fix the public facing IP, but there is no place to edit the local IP. Does anyone know how to edit the nat configuration on centos 6 on Google Compute Engine to fix the local IP so that all new sites created will have the correct local IP in the http.conf?

    Here is a pic of the current nat configuration on my Centos 6 server. enter image description here

    Here is a pic showing my correct local IP in Compute Engine, you can see it does not match the one Cpanel has, which causes the http.conf file to generate new virtual hosts with the wrong IP. enter image description here

  • Chaminda Bandara
    Chaminda Bandara about 2 years
    From where did you get the above knowledge please ?
  • Chaminda Bandara
    Chaminda Bandara about 2 years
    If can not access Panels how to change ? I am getting connection refuse...
  • Desh Deepak Dhobi
    Desh Deepak Dhobi about 2 years
    Yes, You need to change the Public IP assigned for WHM License with the New Public IP. The following documentation link contains the steps on how to do this. support.cpanel.net/hc/en-us/articles/…