Adding/Deleting/Editing a host entry on vCenter server or ESXi host using vi editor
book
Article ID: 345284
calendar_today
Updated On:
Products
VMware vSphere ESXiVMware vCenter Server
Issue/Introduction
This article provides steps for Adding/Deleting/Editing a host entry on vCenter server or ESXi host using vi editor
Resolution
Editing using vi editor
Note: Take a backup of the /etc/hosts file using the command below: cp /etc/hosts /etc/hosts.backup
To add a host entry in /etc/hosts file on a vCenter server or ESXi host:
To edit the /etc/hosts file on a vCenter server or an ESXi host, Login to SSH session for the ESXi host. Login to SSH session for the vCenter server.
Type vi /etc/hosts and press Enter. Now you are in the vi text editor. You can move around using page up, page down, and the arrow keys.
Move down to the last line in the file.
Enter insert mode.
You can press i to start editing where the cursor is, you can also press shift+o to start editing on a new line above the cursor, or o to start editing on a new line below the cursor.
You see -- INSERT -- at the bottom of the vi window while you are in insert mode within vi.
Add the required entry in the below format. <IP address> <FQDN> <shortname>
Note: The number pad on the keyboard does not work within vi by default. Use the numbers above the letters on your keyboard. You can use the arrow, backspace, and delete keys as well as enter text while in edit mode.
To quit and save changes press Esc, :, w, q, then press Enter.
If you decide you are not comfortable with the changes and want to quit without saving, press Esc, :, q, then press Enter. You do not have to press Esc, :, and q at the same time.
To edit an entry in /etc/hosts file on a vCenter server or ESXi host:
To edit the /etc/hosts file on a vCenter server or an ESXi host, Login to SSH session for the ESXi host. Login to SSH session for the vCenter server.
Type vi /etc/hosts and press Enter.
Without entering insert mode move to the character you want to change, press R, then press the key for the character you want to change to.
To save and quit press Esc, :, w, q.
Note: You may receive a warning indicating that the file is read only when you try to save and quit. To get around this, add an ! character to the end of the Esc, :, w, q sequence and press Enter. Note: If you are using putty and you are in insert mode, you can paste clipboard items into vi by left-clicking copied text.
To delete the entries in /etc/hosts file on a vCenter server or ESXi host:
To edit the /etc/hosts file on a vCenter server or an ESXi host, Login to SSH session for the ESXi host. Login to SSH session for the vCenter server.
Type vi /etc/hosts and press Enter to edit the file.
Arrow down to the line to delete.
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.