Adding a new entry to /etc/hosts file when a Linux VM is customized to DHCP IP
search cancel

Adding a new entry to /etc/hosts file when a Linux VM is customized to DHCP IP

book

Article ID: 303157

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

This article provides information about a new entry like 127.0.1.1 newFQDN newHostname being added to the /etc/hosts file in the Linux guest running in a customized VM and how to avoid it if this entry breaks any services.

Note: When a VM with Linux guest is customized with DHCP IP and a new hostname but with no loopback entry like 127.*.*.* FQDN Hostname (127.*.*.* is usually 127.0.0.1) present in its /etc/hosts file, a new entry like 127.0.1.1 newFQDN newHostname will be added to the /etc/hosts file inside the guest.

However, when an entry like 127.0.1.1 FQDN Hostname exists in /etc/hosts inside the guest before customization, customizing the VM with static IP will modify existing loopback entry to 127.0.1.1 newFQDN newHostname and also add a static IP entry like aaa.bbb.ccc.ddd newFQDN newHostname to /etc/hosts file. This may break services that rely on FQDN or Hostname to get IP address.

Resolution

This behavior is as per design.

Workaround:
To work around this issue, use one of these options to avoid 127.0.1.1 FQDN Hostname to be added by guest customization:
 
  • Customize the Linux VM to the static IP aaa.bbb.ccc.ddd directly, then only the static IP entry aaa.bbb.ccc.ddd FQDN Hostname will be added to /etc/hosts file.
  • Customize the Linux VM by cloud-init based guest customization to either DHCP IP or static IP. In this case, no 127.0.1.1 FQDN Hostname entry will be added.