The DNS hosts file is used for mapping hostnames or domain names to IP addresses. You can configure entries in the /etc/hosts
file using esxcli commands, which allows the modifications to remain unchanged while rebooting the ESXi host.
Procedure
- Open an SSH connection to the host.
- Log in as the root user.
- Run the following command.
Option |
Description |
add |
To add the hostname and IP address mapping, run the following command.esxcli network ip hosts add --ip --hostname For example: esxcli network ip hosts add --hostname www.samplehostname.com --ip xx.xx.xx.xx |
remove |
To remove a hostname mapping from the configuration, run the following command.
esxcli network ip hosts remove --hostname
For example: esxcli network ip hosts remove --hostname www.samplehostname.com --ip xx.xx.xx.xx |
list |
To list the IP addresses and their associated DNS entries, run the following command.esxcli network ip hosts list |
Where IP address is the address of the VMkernel adapter, hostname is the DNS entry you want to associate with the IP address, alaises is any aliases you want to associate, and comment is a line about this entry.
Note: ESXCLI network IP hosts add values only to the other hosts. The ESXCLI network IP host does not add values to the current host. The information about the current host is managed through the host name under the
Network Settings. If you try to change the current hostname you might see an error similar to the following:
Error adding etc host item: User can not set item for management IP: X.X.X.X
For information on changing the host name of the current host, see Change the Configuration of a TCP/IP Stack on a Host.