What's the "Correct" Way to Set Hostname?

3,289 views
Skip to first unread message

Les Bell

unread,
Aug 4, 2015, 6:49:49 PM8/4/15
to gce-discussion
I've set up a CentOS 7.1 instance as my first experience with GCE. Everything is going quite smoothly and I've worked out how to do most things like setting up SSH keys, etc. but one thing still has me stumped: setting the hostname.

If I use the "hostnamectl set-hostname" command to set the hostname from a shell, everything's fine and it takes. However, upon reboot, I've discovered that the GCE startup script sets the transient hostname back to "instance-1":

[lesbell@instance-1 ~]$ sudo hostnamectl status
   Static hostname: svalbard.lesbell.com.au
Transient hostname: instance-1
         Icon name: computer-vm
           Chassis: vm

Which leads me to ask: what's the canonically correct way (i.e. the way Google intends) to set the hostname? I don't think it can be from the instance name, since an instance name can only consist of letters, digits and hyphens. Is it set from some other metadata somewhere? Or should I hack the startup script (but then it might get rewritten again later)? Or just add my own startup script? Or something else entirely?

--- Les

Alex Martelli

unread,
Aug 4, 2015, 7:47:40 PM8/4/15
to Les Bell, gce-discussion
Several fine approaches are at http://stackoverflow.com/questions/25408612/google-compute-engine-how-to-set-hostname-permanently -- including a comment by the OP "I settled with the advice not to change the hostname, because it is not necessary":-).

Google's official docs, at https://cloud.google.com/compute/docs/images?hl=en , point 5, recommend to "Edit /etc/rc.local to set the hostname at boot, so that the instance boots with the name you give the instance in Compute Engine" (which is also among the answers in the above SO question).


Alex


--
© 2014 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Compute Engine Discussion Google Group (gce-dis...@googlegroups.com) to participate in discussions with other members of the Google Compute Engine community and the Google Compute Engine Team.
---
You received this message because you are subscribed to the Google Groups "gce-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gce-discussio...@googlegroups.com.
To post to this group, send email to gce-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gce-discussion/a8881249-c8d9-4501-9d7a-13fbc758f15f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Les Bell

unread,
Aug 4, 2015, 7:58:15 PM8/4/15
to gce-discussion, les...@lesbell.com.au
Thanks, Alex - I'll go with that. I found setting the hostname correctly was necessary in order to relay outbound email through Google Apps via smtp-relay.gmail.com:587 - until that was done, the smtp-relay machine was refusing to relay outbound emails.

--- Les
Reply all
Reply to author
Forward
0 new messages