Modifying host entry in /etc/hosts file for vCenter or ESXi host using vi editor
search cancel

Modifying host entry in /etc/hosts file for vCenter or ESXi host using vi editor

book

Article ID: 345284

calendar_today

Updated On:

Products

VMware vSphere ESXi VMware vCenter Server

Issue/Introduction

  • A DNS resolution failure halts ESXi and vCenter communication via FQDN, causing vSphere outages (e.g., unresponsive hosts, HA failures).
  • An immediate mitigation is to restore DNS resolution by manually adding host entries on the vCenter Server or ESXi host /etc/hosts file.
  • To validate an ESXi host or vCenter has DNS resolution issue, run the following command:

nslookup <hostname.example.com>

Example for a failed DNS resolution:

root@<host> [ ~ ]# nslookup hostname.example.com
;; connection timed out; no servers could be reached

Example for a successful DNS resolution:

root@<host> [ ~ ]# nslookup hostname.example.com
Server:     <DNS_Server>.example.com
Address:     <###.##.##.###>#53

Name:   hostname.example.com
Address: ###.##.##.###

Environment

  • ESXi 7.x
  • ESXi 8.x
  • ESX 9.x
  • vCenter 7.x
  • vCenter 8.x
  • vCenter 9.x

Resolution

  • Take a backup of the /etc/hosts file using the command below:

cp /etc/hosts /etc/hosts.backup

Note: Changes made to /etc/hosts on ESXi host 7.0 U3 and above is not persistent after an ESXi reboot. Use ESXCLI method to add or remove the host entry: Configure the DNS Hosts File by Using ESXCLI Commands

  • To add or edit host entries in the /etc/hosts file for ESX host 7.0 U3 and below or for vCenter Server, follow the below steps:

1. Login to ESXi host or vCenter via SSH as a root user

2. Use vi editor to edit the /etc/hosts file.

vi /etc/hosts

3. Add or edit or delete a host entry in the /etc/hosts file:

Table of Contents:

a. Add a host entry in the /etc/hosts file on a vCenter server or ESXi host.

b. Edit a host entry in the /etc/hosts file on a vCenter server or ESXi host.

c. Delete a host entry in the /etc/hosts file on a vCenter server or ESXi host.

3(a) Add a host entry in the /etc/hosts file on a vCenter server or ESXi host:

1. In the vi editor, press i to enter in to insert mode to start editing where the cursor is, or press o to start editing on a new line below the cursor. The bottom of the vi editor may show -- INSERT -- while the insert mode is active within vi.

2. Add the required host entry at the bottom line in the below forma.

<IP address> <hostname.example.com> <host_shortname>

Example: 192.##.##.### hostname.example.com hostname

3. Save the file and exit (press ESC, type :wq!, press Enter).

4. To exit vi editor without saving the file, press Esc, type :q, then press Enter.

3(b) Edit a host entry in the /etc/hosts file on a vCenter server or ESXi host:

1. In the vi editor, without entering insert mode, use the arrow keys to move to the character that needs to be modified, press R, then press the key for the character you want to change to. This option can be used to modify minor changes like IP address, hostname.

2. Save the file and exit (press ESC, type :wq!, press Enter).

3. To exit vi editor without saving the file, press Esc, type :q, then press Enter.

3(c) Delete a host entry in the /etc/hosts file on a vCenter server or ESXi host.

1. In the vi editor, use arrow keys to point the cursor to the host entry that needs to be delete.

2. Press d twice to delete the whole line. You can also press x to delete only one character at a time when you are not in insert mode.

3. Save the file and exit (press ESC, type :wq!, press Enter).

4. To exit vi editor without saving the file, press Esc, type :q, then press Enter.