2

I'm trying to figure out how to set a new hostname for my GCE Instance running Denial Linux I came about many different "solutions" so I got a bit lost.

I would like to know what is the best practice to achieve it.

Also do I need to change /etc/hosts or will it get updated automatically with my new hostname ?

Thank you very much for your kind help!

Suggestion: Google should put a specific page in it's doc to document the process

1

As explained in the following documentation "hostname" is part of the default metadata entries and it is not possible to manually edit any of the default metadata pairs.

A post by a GCE Product Manager shows that Google is aware of this issue and are actively working on a feature which will allow you to change VM hostname, but, there’s no ETA. at this time.

That being said, if you still wish to alter this process by changing the "hostname" before the feature is release, there's a couple of workarounds available.

You set that attribute for the file you do not want to change e.g. the hostname file, immutable. You can make the /etc directory including all its content immutable using the following command:

$ sudo chattr -R +i /etc 

Or, set that attribute for the file you do not want to change which would be the host's file, using the following command.

$ sudo chattr -i /etc/google_hostname.sh 

For more information on making files and directory immutable in Linux, you can see the following article

or see the following Google group article for some examples

Alternatively, as suggested on the GCE public doc you can make static modifications in the resolv.conf file, several Linux distributions allow items to be prepended or appended to the DHCP policy" but I'm unable to confirm what impact this might have on the VM.

You can file a report on User Voice Forum for Documentation feedback (incorrect documentation, general feedback, suggestions)

1

I would like to let you know the alpha feature released and there is possibility to set a new name of a a Google Compute Engine virtual machine. Please note this command is currently in ALPHA and may change without notice.

gcloud alpha compute instances set-name INSTANCE_NAME --new-name=NEW_NAME [--zone=ZONE]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.