标题说明了这一切 – 我想更改Google计算引擎Cent OS实例的主机名。
我已经尝试了正常的方法…
/etc/sysconfig/network设置HOSTNAME=my.new.hostname /etc/hosts设置127.0.1.1 my.new.hostname 我已经尝试在Compute Engine VM Instancepipe理页面的Custom metadata中设置hostname键/值对。
没有什么坚持。 似乎使用实例名称作为主机名。
默认情况下有一个启动脚本,根据该实例的元数据设置主机名。
请参阅: https : //github.com/GoogleCloudPlatform/compute-image-packages/tree/master/google-startup-scripts
Sets the hostname from the metadata server via DHCP exit hooks.
你尝试过主机名(1)吗?
主机名是用于设置或显示系统的当前主机,域或节点名称的程序。 这些名称被许多networking程序用来识别机器。
hostname xyzzy.example.com hostname plugh.example.com hostname plugh.example.com
在Google计算引擎(Cent OS)中更改主机名
步骤1
# nano /etc/sysconfig/network NETWORKING=yes HOSTNAME=my.new.hostname
第2步:创buildcrontab自动设置主机名
# crontab -e @reboot hostname="my.new.hostname"; sed -i "s/.*Google.*//" /etc/hosts; hostname "$hostname"
第3步
# reboot
第4步:在下面添加
# nano /etc/hosts 127.0.0.1 my.new.hostname