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

Sunny J
  • 607
  • 3
  • 14
jlkreiss
  • 21
  • 1

2 Answers2

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]
Stuggi
  • 3,506
  • 4
  • 19
  • 36
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)

Sunny J
  • 607
  • 3
  • 14