Cloud-Based Hostname Workaround

It’s very common these days for hosting providers to offer cloud-based hosting solutions to their customers. In configuring these servers ourselves, and in interactions with our customers’ servers, an issue has come to our attention where the dhclient script does not preserve locally-configured hostnames. This means that hostnames configured on the command line might not remain through a reboot. We wante to provide a workaround solution for this while continuing to investigate a more permanent, long-term solution. What …

Spread the love

It’s very common these days for hosting providers to offer cloud-based hosting solutions to their customers. In configuring these servers ourselves, and in interactions with our customers’ servers, an issue has come to our attention where the dhclient script does not preserve locally-configured hostnames. This means that hostnames configured on the command line might not remain through a reboot. We wante to provide a workaround solution for this while continuing to investigate a more permanent, long-term solution.

What is the issue?

For many cloud hosting providers, configuring automated deployments is done by invoking the dhclient script at boot-time, which includes configuring the server’s hostname incorrectly. Commonly, hosting providers will use additional scripting to work around this issue. For example, Google Cloud Engine uses the google_set_hostname script.

However, this solution creates a new problem: these scripts may interfere with WHM’s Change Hostname feature (WHM >> Home >> Networking Setup >> Change Hostname). If your hostname is set in WHM to something that conflicts with the hostname set by the dhclient script, there will be problems in cPanel & WHM, up to and including the invalidation of the server’s cPanel Software license.

The workaround

To resolve this issue, you must create a dhclient exit hook script, which will then set the hostname properly at boot-time. You first create a script like the one below, which we have named set-hostname.sh, in the /etc/dhcp/dhclient-exit-hooks.d/ directory. In this example, replace hostname.example.com with your desired server hostname:

You can also use the below command to create the script, input the proper information, and set the file’s permissions correctly. Make sure to replace hostname.example.com with your desired hostname:

mkdir -p /etc/dhcp/dhclient-exit-hooks.d/ && echo -ne '#!/bin/sh\nhostname hostname.example.com\n/scripts/fixetchosts\n' > /etc/dhcp/dhclient-exit-hooks.d/set-hostname.sh && chmod +x /etc/dhcp/dhclient-exit-hooks.d/set-hostname.sh

If you have any further questions or concerns, comment below, or reach out to us via our Slack or Discord channels, or join the discussion on the Official cPanel & WHM Subreddit!

Facebook Comments

More Stuff

API basics and how to call API1 functions I have been noticing several people challenged with calling cPanel functions via our various ways of hooking into our APIs. Unfortunately, this isn’t ...
WHM Frames Have Left the Building Though we have mentioned the motion a couple times before, we wanted to post a quick note for everyone now that we’re getting close to releasing cPane...
WordPress/Joomla!/Drupal- A Security Comparison One of the more popular methods of publishing content on a website is a CMS (Content Management System). A CMS generally has a graphic user interface ...
5 Reasons You Want to be Using EasyApache 4 EasyApache 4 was introduced in cPanel & WHM version 11.52 and has grown into a stable and mature product. As of version 58 EasyApache 4 is out of ...
Spread the love

Posted by News Monkey