Google compute engine 谷歌云计算引擎/etc/hosts

Google compute engine 谷歌云计算引擎/etc/hosts,google-compute-engine,Google Compute Engine,在我的谷歌云计算引擎中,/etc/hosts文件会在一段时间后自动覆盖 请告诉我为什么会发生这种情况以及如何预防 最初的条目如下: 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.128.0.2 instance-1.c.

在我的谷歌云计算引擎中,/etc/hosts文件会在一段时间后自动覆盖

请告诉我为什么会发生这种情况以及如何预防

最初的条目如下:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

10.128.0.2 instance-1.c.concrete-craft-123421.internal instance-1  # Added by Google
为了启动cloudera服务,我将其更改为如下

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#10.128.0.2 instance-1.c.concrete-craft-123421.internal instance-1  # Added by Google

10.128.0.2 instance-1 instance-1
但过了一段时间,原来的条目又出现了。你知道这是什么原因吗

谢谢,

在谷歌计算引擎实例上,有一些在后台运行的Nanda。这些守护程序服务负责以下服务:

1. Creates new accounts based on the instance metadata.
2. Configures SSH to accept the accounts' public keys from the instance metadata.
3. Adds IP addresses of network load balancers as aliases of the external Ethernet interface
4. Resyncs clock if skewed due to live migration

/etc/hosts由这些守护程序服务管理和覆盖。因此,如果希望永久更改实例的主机名,可以通过在实例上创建cron作业来实现。您可以通过以下步骤创建cron作业。

您可以做什么来代替此操作

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#10.128.0.2 instance-1.c.concrete-craft-123421.internal instance-1  # Added by Google

10.128.0.2 instance-1 instance-1
你的台词太多了

10.128.0.2 instance-1 instance-1
在谷歌产品线之前。而且不需要cron;)它不会被删除

这样做->

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

10.128.0.2 instance-1 instance-1

#10.128.0.2 instance-1.c.concrete-craft-123421.internal instance-1  # Added by Google

我在RHEL7+NetworkManager上遇到了同样的问题,这就是我如何防止这种情况再次发生的原因:

tee /etc/dhcp/dhclient.d/1-google_hostname_off.sh << EOF
#!/bin/bash
# Block hosts changes by google-compute-engine
google_hostname_config() {
    :;
}
readonly -f google_hostname_config
EOF
chmod +x /etc/dhcp/dhclient.d/1-google_hostname_off.sh
tee/etc/dhcp/dhclient.d/1-google\u hostname\u off.sh看,这是google放进去的dhclient出口钩子。