0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

IBM Cloud: (小ネタ)VPCで/etc/hostsに追加した情報がrebootした際に消される問題について

Last updated at Posted at 2020-11-16

#問題

/etc/hostsへのレコード情報の追加
[root@syssuda5-vpc2 ~]# echo "8.8.8.8   googledns" >> /etc/hosts
pingに成功
[root@syssuda5-vpc2 ~]# ping -c 3 googledns
PING googledns (8.8.8.8) 56(84) bytes of data.
64 bytes from googledns (8.8.8.8): icmp_seq=1 ttl=119 time=13.6 ms
64 bytes from googledns (8.8.8.8): icmp_seq=2 ttl=119 time=1.02 ms
64 bytes from googledns (8.8.8.8): icmp_seq=3 ttl=119 time=0.999 ms

--- googledns ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.999/5.220/13.634/5.949 ms

しかし、再起動したらまたpingができなくなっています。

再起動後。pingに失敗。
[root@syssuda5-vpc2 ~]# ping -c 3 googledns
ping: googledns: 名前またはサービスが不明です
再起動後。/etc/hostsから追加したはずのレコードが削除されている。
[root@syssuda5-vpc2 ~]# cat /etc/hosts
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.redhat.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
#     /etc/cloud/cloud.cfg or cloud-config from user-data
#
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 syssuda5-vpc2 syssuda5-vpc2
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4

# The following lines are desirable for IPv6 capable hosts
::1 syssuda5-vpc2 syssuda5-vpc2
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

#解決方法

/etc/hostsのヘッダ部分に書かれているとおり、cloud-initで上書きされてしまったためです。/etc/cloud/cloud.cfgにて、manage_etc_hosts: Trueの箇所をコメントしてしまいます。

/etc/cloud/cloud.cfg(before)
manage_etc_hosts: True
/etc/cloud/cloud.cfg(after)
#manage_etc_hosts: True

これで再起動後に/etc/hostsがcloud-initによって上書きされることがなくなりました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?