Google Compute Engine: how to set hostname permanently?

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

    There is some hack you can do to achieve this as i did. Just do:

    sudo chattr +i /etc/hosts
    

    This command actually makes the file "(i)mmutable", which means even root can't change it (unless root does chattr -i /etc/hosts first, of course).

    As above, you can undo this with sudo chattr -i /etc/hosts

    Cheer!

提交回复
热议问题