skip to Main Content

I’ve had to change hostname on a Google Cloud Compute that is running a WHM instance, but it keeps resetting every now and then and restart.

My /etc/hosts are currently as follow:

127.0.0.1               localhost localhost.localdomain localhost4 localhost4.localdomain4
::1             localhost localhost.localdomain localhost6 localhost6.localdomain6
10.156.0.7 cpanel.server-location-c.c.ascendant-hub-hidden.internal cpanel  # Added by Google
169.254.169.254 metadata.google.internal  # Added by Google

My System Information are:
Linux cpanel.xxx.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

My Old Hostname is something alike:
cpanel.xxx.com

I want my new hostname to become:
brain.xxx.com

Even when I change it from WHM using their Change Hostname feature, it keeps resetting.

Is their a cleaner method then setting a crontab?

2

Answers


  1. Unfortunately, you’re not able to change a custom hostname after you’ve created VM instance. Have a look at the documentation Creating a VM instance with a custom hostname:

    You can create a VM with a custom hostname by specifying any fully
    qualified DNS name.

    and at the section Limitations:

    You cannot change a custom hostname after you have created the VM.

    To change this behavior you can try to file a feature request at Google Issue Tracker under this component.

    UPDATE In addition, have a look at the documentation Storing and retrieving instance metadata section Default metadata keys:

    Compute Engine defines a set of default metadata entries that provide
    information about your instance or project. Default metadata is always
    defined and set by the server. You can’t manually edit any of these
    metadata pairs.

    and hostname is part of the default metadata entries and could not be changed manually.

    UPDATE 2 As a possible workaround, you can use a startup script or other solutions to change the hostname every time the system restarts, otherwise it will automatically get re-synced with the metadata server on every reboot. For example, I applied this startup script via Custom metadata:

    Key: startup-script
    Value: #! /bin/bash 
           hostname changed-host-name'
    

    then restarted VM instance and it works for me:

    changed-host-name:~$ hostname
    changed-host-name
    
    Login or Signup to reply.
  2. These are few ways to change your hostname:

    1. One way is to edit /etc/hostname directly – just switch file content with your new hostname.
    2. The other way is to use hostnamectl set-hostname <your new hostname> which change /etc/hostname file for you.

    But I think your problem is that Google keeps to overwrite some data not only when you reboot system but also while your VM is running. Assuming that above solutions, won’t solve your issue.

    Solution:

    Thankfully Google Cloud Platform allows you to have custom hostname but you have to define them when creating new virtual instance. Check out this GCP document.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search