Google Compute Engine: how to set hostname permanently?

前端 未结 14 1628
萌比男神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:22

    I was lucky to set hostname at GCE running CentOS. Source: desantolo.com

    1. Click EDIT on your instance
    2. Go to "Custom metadata" section
    3. Add hostname + your.hostname.tld (change "your.hostname.tld" to your actual hostname
    4. run curl --silent "http://metadata.google.internal/computeMetadata/v1/instance/attributes/hostname" -H "Metadata-Flavor: Google"
    5. run sudo env EDITOR=nano crontab -e to edit crontab
    6. add line @reboot hostname $(curl --silent "http://metadata.google.internal/computeMetadata/v1/instance/attributes/hostname" -H "Metadata-Flavor: Google")
    7. On your keyboard Ctrl + X
    8. On your keyboard hit Y
    9. On your keyboard hit Enter
    10. run reboot
    11. after system rebooted, run hostname and see if your changes applied

    Good luck!

提交回复
热议问题