ESXi Setting a static IP - 夜莺博客

ESXi Setting a static IP

原文:ESXi Setting a static IP — theDXT (Daniel Keer)

Here is how to set a static IP in ESXi. This guide follows the original Host Client walkthrough (Networking > VMkernel NICs > vmk0 > Edit settings) and then extends it with the DCUI and ESXCLI equivalents, the VLAN and DNS settings you will usually need at the same time, and the failure modes that bite when you repoint the management interface of a live host.

Why the management interface must be static

The management network (vmk0 on the default TCP/IP stack) carries everything that makes the host manageable: the Host Client, ESXCLI over SSH, vCenter's connection to hostd/vpxa, NTP, syslog, SNMP, Active Directory integration and, on many installations, iSCSI or NFS traffic to the array.

  • A DHCP lease that expires or is handed to another device takes the host out of vCenter. The host keeps running its VMs — it simply becomes unmanageable, often at the exact moment you need it.
  • vCenter, backup software and monitoring tools remember the address. A changed address means reconnecting and re-registering hosts.
  • DHCP does not create a PTR record you can rely on, and ESXi will log "name of the host does not resolve" style warnings when reverse lookup fails.
  • Firewall rules, iSCSI initiator groups, NFS export ACLs and array host definitions are all bound to the address.

Use DHCP only while building or in throwaway labs where the management address changes on purpose. For anything you will manage, static is the default.

Prerequisites and preparation

  • Out-of-band access. If the new IP is wrong you cannot reach the host over the network any more. Have iDRAC/iLO/IPMI/KVM or a physical console available for the whole change.
  • A free address in the same subnet and VLAN as the existing management network, excluded from the DHCP pool, and confirmed as unused (ping and check the ARP table of the gateway, or ask the network team).
  • Subnet mask and default gateway, and confirmation of which switch port VLAN the host is cabled to.
  • DNS servers and search domain (for example 10.10.10.5 and lab.example.com).
  • Version: ESXi 6.5 through 8.0 use the same UI paths and identical ESXCLI syntax. Screenshots in this article are from ESXi 7.
  • A maintenance window when the host is in vCenter, or at least confirm that no task (migration, backup, VM clone) is in flight.
  • Record the current state — this is your rollback information:
# Over SSH (Host > Manage > Services > TSM-SSH > Start)
esxcli network ip interface list
esxcli network ip interface ipv4 get
esxcli network ip route ipv4 list
esxcli network vswitch standard portgroup list

Method 1: ESXi Host Client (GUI)

Log in to the Host Client at https://<current-management-ip>/ui, then follow the original walkthrough.

  1. Go to Networking (in the Host Client this is Host > Manage > Networking).

Image 3

  1. Click on VMkernel NICs.

Image 4

  1. Click on vmk0.

Image 5

  1. Click Edit settings.

Image 6

  1. Expand the IPv4 settings section and switch it from DHCP to Static, then give it the static IP, the subnet mask and the default gateway. The VLAN ID field on this dialog is the port group VLAN — leave it at 0 if your switch port is untagged.

Image 7

  1. Click Save. Just like that ESXi now has a static IP.

Important: the moment you save, the management address changes. Your browser session dies mid-request and vCenter will shortly mark the host as Not responding. That is normal — reconnect to https://<new-ip>/ui and fix vCenter afterwards.

Method 2: Direct Console User Interface (DCUI)

Use this when you have console access but no working network management, or when you have just locked yourself out and need to put the address back.

  1. Press F2 and log in as root.
  2. Select Configure Management Network.
  3. Select IPv4 Configuration.
  4. Choose Set static IPv4 address and network configuration with the space bar, then fill in IPv4 Address, Subnet Mask and Default Gateway. Press Enter.
  5. Optionally select VLAN (optional) and enter the VLAN ID if the switch port is a trunk.
  6. Press Esc to leave the menu and answer Y to Apply changes and restart management network?
  7. If the change seems not to apply, use Troubleshooting Options > Restart Management Agents (F11 twice).

Method 3: ESXCLI over SSH

The CLI route is faster and scriptable, and it is the only sane way to touch a host when the Host Client is not loading.

# 1) Show the current addressing
esxcli network ip interface ipv4 get

# 2) Switch vmk0 from DHCP to a static address
esxcli network ip interface ipv4 set -i vmk0 -t static \
  -I 10.10.10.20 -N 255.255.255.0 -G 10.10.10.1

# 3) Confirm
esxcli network ip interface ipv4 get
esxcli network ip route ipv4 list

If the management traffic must be tagged, set the VLAN on the port group that carries vmk0:

esxcli network vswitch standard portgroup list
esxcli network vswitch standard portgroup set -p "Management Network" -v 20
esxcli network vswitch standard portgroup list

Then fix name resolution in the same session, so the new address is actually resolvable both ways:

esxcli network ip dns server add -s 10.10.10.5
esxcli network ip dns server add -s 10.10.10.6
esxcli network ip dns search add -d lab.example.com
esxcli network ip dns server list

If the host name and address have both changed, set the name too:

esxcli system hostname set --fqdn=esxi01.lab.example.com
esxcli system hostname get

Adding additional VMkernel interfaces

Once vmk0 is static, most installations want at least one more VMkernel NIC — for iSCSI, vMotion or a dedicated backup network. The pattern is identical: create the port group, add the interface, give it a static address, and tag it for its role.

# iSCSI storage network
esxcli network ip interface add -i vmk1 -p "iSCSI-A" -M 1500
esxcli network ip interface ipv4 set -i vmk1 -t static -I 10.20.20.20 -N 255.255.255.0
esxcli network ip interface tag add -i vmk1 -t iSCSI

# vMotion
esxcli network ip interface add -i vmk2 -p "vMotion" -M 1500
esxcli network ip interface ipv4 set -i vmk2 -t static -I 10.30.30.20 -N 255.255.255.0
esxcli network ip interface tag add -i vmk2 -t VMotion

Note that a storage vmkernel interface normally has no default gateway — it only needs to reach its array in the same subnet. Only vmk0 should carry the default route; additional default routes on a VMkernel adapter cause routing surprises that are painful to debug.

Verification

# Addressing, routes and interfaces
esxcli network ip interface ipv4 get
esxcli network ip route ipv4 list

# Reach the gateway from the management interface itself
esxcli network diag ping -H 10.10.10.1 -I vmk0

# Reach a host by name (tests DNS, not just routing)
esxcli network diag ping -H esxi01.lab.example.com -I vmk0

# Management services answer on the new address
esxcli network ip connection list | grep 443
  • From a workstation in the same VLAN: ping 10.10.10.20, then browse to https://10.10.10.20/ui and confirm you can log in.
  • From a different VLAN: confirm end-to-end routing and firewall rules allow 443 and 902 (vSphere Client and VM console).
  • In vCenter: the host should return to Connected on its own, or after Disconnect/Connect. Confirm no address-mismatch alarms remain.
  • If you use iSCSI, run a rescan (Storage > Adapters > Rescan) after the change and confirm the LUNs are still visible.
  • Confirm the NTP client recovered: ntpq -p should show a reachable peer.

Common problems

I lost access to the host completely. Use the DCUI (or iDRAC/iLO KVM) to check what is configured: Configure Management Network > IPv4 Configuration. Nine times out of ten it is a wrong gateway, a subnet mask of 255.255.0.0 instead of 255.255.255.0 (or vice versa), or an address that is already in use on another device.

The host dropped out of vCenter. Expected. Reconnect it, and if vCenter is configured to connect by name, make sure the A record for the FQDN now points to the new address. Check for the "name and address do not match" style alarms once it reconnects.

Ping works on the host but nothing else does. This is almost always a VLAN mismatch: the port group has no VLAN ID while the switch port is a trunk (or the reverse). Check esxcli network vswitch standard portgroup list and compare it with the switchport configuration.

"Duplicate IP address detected" in the VMkernel log. Something else is using the address — a stale DHCP lease, a second host, or a misconfigured VM port group. Move the host to a different address and find the conflict before continuing.

You can reach the host by IP but management tools fail after the change. Those tools cache the old address; update the host entry in vCenter, backup software, monitoring, syslog and SNMP target lists.

After changing vmk0, iSCSI traffic broke. Port binding configuration references the VMkernel interface by name, not address, so it usually survives — but if the management and storage traffic share one vmk0, moving the address can move the storage path with it. Best practice is a dedicated VMkernel interface for storage, as shown above.

The setting reverts after a reboot. It does not, if you used the Host Client, DCUI or esxcli — all three persist. It will revert if the host is enrolled in a vCenter host profile that enforces the old address, or if the host is re-added from a template image. Fix the source of truth rather than the host.

I need to keep the old address temporarily. Run the old and new addresses in parallel by adding a second VMkernel interface with the old address or a secondary IP, migrate the dependent systems (vCenter, backup, monitoring), and only then remove it. This avoids a hard cut-over window.

Rollback

From the DCUI or a console session, set the previous address back:

# DCUI: F2 > Configure Management Network > IPv4 Configuration > Set static IPv4 address...
# or over SSH / console shell:
esxcli network ip interface ipv4 set -i vmk0 -t static \
  -I 10.10.10.10 -N 255.255.255.0 -G 10.10.10.1
esxcli network ip dns server add -s 10.10.10.5

Keep the pre-change output of esxcli network ip interface ipv4 get, esxcli network ip route ipv4 list and esxcli network ip dns server list in your change ticket; rollback then takes under a minute.

Summary

Setting a static IP on ESXi is one dialog in the Host Client, one menu in the DCUI, or a single esxcli network ip interface ipv4 set -i vmk0 -t static ... command. The parts people forget are the ones that cause the outages: keep out-of-band access, use a verified free address, fix the VLAN and DNS in the same window, expect vCenter and monitoring to need a reconnect, and verify forward and reverse resolution from a second system before closing the change.