Google Compute Engine: how to set hostname permanently?

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

    When creating a VM, you can 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 prevent the need for workaround scripts. More info in the docs.

    -- Sirui (Product Manager, Google Compute Engine)

    0 讨论(0)
  • 2020-12-29 07:25

    Edit rc.local

    sudo nano /etc/rc.local 
    

    Add your line under the rest:

    hostname *your.hostname.com*
    

    Make sure to run the following after for the script to be executed

    chmod +x /etc/rc.d/rc.local
    

    Reboot, and profit.

    0 讨论(0)
提交回复
热议问题