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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s