Skip to content

Instantly share code, notes, and snippets.

@yuki-takeichi
Created July 13, 2016 06:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuki-takeichi/3080521322f0f1d159ea6a343e2323e6 to your computer and use it in GitHub Desktop.
Save yuki-takeichi/3080521322f0f1d159ea6a343e2323e6 to your computer and use it in GitHub Desktop.
Configuring FQDN for GCE instance
diff -Naur before/usr/share/google/set-hostname after/usr/share/google/set-hostname
--- before/usr/share/google/set-hostname 2016-03-16 18:30:48.000000000 +0900
+++ after/usr/share/google/set-hostname 2016-03-16 18:34:57.000000000 +0900
@@ -14,6 +14,9 @@
# Deal with a new hostname assignment.
+# *** The below line is added by patching. ***
+new_host_name=$(curl --fail --silent http://metadata/computeMetadata/v1/instance/attributes/hostname -H "Metadata-Flavor: Google")
+
if [ -n "$new_host_name" ] && [ -n "$new_ip_address" ]; then
# Delete entries with new_host_name or new_ip_address in /etc/hosts.
sed -i '/Added by Google/d' /etc/hosts
@edzeldiana
Copy link

Do you have a steps by steps on how to do this on my GCE instances CentOS?

@alexszilagyi
Copy link

@edzeldiana: its only one step, run this command: sudo sed -i "\$ahostname YourFQDN" /etc/dhcp/dhclient-exit-hooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment