Google Cloud Engine + cPanel: Set Hostname (Workaround)

Minuwan Deshapriya
HackerNoon.com
2 min readJun 4, 2019

--

Photo by Benjamin Dada on Unsplash

I guess many of you are already using cloud based hosting solutions with WHM (cPanel) setup to provide web hosting solutions to customers or for your own projects to host websites and applications.

In many cases I use DigitalOcean for my hosting needs, But I noticed a weird issue while I working with Google Cloud Engine that I didn’t catch when working with DigitalOcean droplets (Later found out, this is common issue for few more cloud based hosting solutions as well). Which is, hostnames configured on the command line not remain through a reboot.

The issue, in detail.

Most cloud hosting providers configure automated deployments by calling a dhclient script when booting, But this generates the server’s hostname incorrectly. To overcome this issue most hosting providers are using a additional script as a workaround such as google_set_hostname on Google Cloud Engine. This is OK in many cases, but the above mentioned problem arise when some services like WHM/cPanel are using dhclient script to set machine’s hostname (WHM > Home > Networking Setup > Change Hostname) on the go. This may drives to a “Invalid” cPanel licence error as well in some cases.

The solution number: ONE.

If you were using:

Instead use:

In many cases this will fix the issue. But if that’s not helping, I have found another solution for you.

The solution number: TWO.

If the first option didn’t worked out for you, You can set a “exit” hook script which will set the hostname properly at boot-time. Remember to replace hostname.example.com with your own hostname.

This script will create a script named set-hostname.sh in the /etc/dhcp/dhclient-exit-hooks.d/ directory with required permissions to run.

Follow me on: Medium Minuwan Deshapriya, Twitter @twitminu or Facebook @minuwan.

--

--