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 …

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!

Posted by Web Monkey

Leave a Reply