Google Compute Engine: how to set hostname permanently?

前端 未结 14 1511
萌比男神i
萌比男神i 2020-12-29 06:32

How do I set the hostname of an instance in GCE permanently? I can set it via hostname,but after reboot it is gone again.

I tried to feed in metadata (hostname:f.q.d

14条回答
  •  孤城傲影
    2020-12-29 07:17

    You can also create a simple startup-script to do the jobs:

    $ gcloud compute instances add-metadata  --zone  --metadata startup-script='#! /bin/bash 
    hostname '
    

    Notice that if you already have a startup-script you need to add to the existing startup-script below command or you will replace all the startup-script:

    $ hostname instance-name
    

提交回复
热议问题