How to make hostname permanent on google cloud engine (GCE)

syntax:

gcloud compute instances add-metadata <instance-name> –zone <instance-zone> –metadata startup-script=’#! /bin/bash hostname <hostname>’

Open gcloud shell :

gcloud compute instances add-metadata cms –zone us-central1-c –metadata startup-script=’#! /bin/bash hostname your.hostname.com’

Welcome to Cloud Shell! Type “help” to get started.
mshaikdevops@rising-artifact-164906:~$ gcloud compute instances add-metadata cms –zone us-central1-c –metadata startup-script=’#! /bin/bash hostname cms.puppethub.in’
Updated [https://www.googleapis.com/compute/v1/projects/rising-artifact-164906/zones/us-central1-c/instances/cms].

$ sudo crontab -e
@reboot hostname $(curl –silent “http://metadata.google.internal/computeMetadata/v1/instance/attributes/hostname&#8221; -H “Metadata-Flavor: Google”)

vim /etc/rc.local
hostname *your.hostname.com*
chmod +x /etc/rc.d/rc.local

Leave a comment