how can i change hostname in GCE

3,648 views
Skip to first unread message

Muhammad Yousuf Khan

unread,
Feb 8, 2016, 8:18:37 AM2/8/16
to gce-discussion
Dear All,

I am new to google cloud compute engine. and i want to change the Hostname of a compute engine. having  Debian Jessie or 8.x.
amazingly i can not see the file. /etc/hostname  normally where we change the hostname. i do not like the default name of the instance. 

please help.

Thanks,
Yousuf

George

unread,
Feb 8, 2016, 2:29:21 PM2/8/16
to gce-discussion
Hello Yousuf,

As the hostname is set via a DHCP exit hook and will be re-configured  to match the instance name anytime the network is brought up,  you will need to either change it every-time the instance reboots using a script and a cronjob, or by creating a startup script in the instance metadata. Both solutions are mentioned in this StackOverflow post.

I hope this helps.

Sincerely,
George

Muhammad Yousuf Khan

unread,
Feb 9, 2016, 5:23:49 AM2/9/16
to gce-discussion
Thanks George it really help :)

XOOM SERVE

unread,
Jan 19, 2018, 9:01:04 PM1/19/18
to gce-discussion
Hi George,

In the current GPC KVM, I did every possible solution mentioned in the internet including your link.
But again my host name is keep changing.

Whats happening now, that the script is start fine with the pre defined Host name, and with no reason its changed again even if the KVM never rebooted.

Can you advise please?

My cPanel license blocked twise because of this issue.

Thank you,
Tariq

Sirui Sun

unread,
Nov 9, 2018, 1:55:47 PM11/9/18
to gce-discussion
Hi Yousuf - when creating a VM, you can now specify a custom FQDN hostname as an optional parameter. This feature is currently in Beta. 

$ gcloud beta compute instances create INSTANCE_NAME --hostname example.hostname

This should work across OSes, and eliminate the need for workaround scripts.

More info in the docs.

Sirui Sun
Product Manager | Google Compute Engine
Reply all
Reply to author
Forward
0 new messages