Configuring vSwitch or vNetwork Distributed Switch from the command line in ESXi/ESX
search cancel

Configuring vSwitch or vNetwork Distributed Switch from the command line in ESXi/ESX

book

Article ID: 326175

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article provides commands and information to restore management network connectivity via the correct vmnic interface.
See also: vCenter network connectivity lost - Recover vCenter network when connected to a Distributed Switch

Symptoms:
  • You are unable to connect to an ESXi/ESX host via the network because uplinks (vmnics) have changed or are not in the correct order
  • The Primary Service Console/VMkernel management interface is moved from a switch to a distributed switch on a non-routable network
  • VLAN for the Management Network is changed or configured incorrectly on the uplink Switch Port


Environment

VMware vSphere ESXi 8.0.x
VMware vSphere ESXi 7.0.x
VMware vSphere ESXi 6.x

Resolution

Notes:

  • You can restore the network to a Standard vSwitch using the Restore Standard Switch option from the Direct Console User Interface (DCUI) console screen (press F2 from console). This results in a blank network configuration (1 x vSwitch with 1 x vmkernel port group) on the ESXi host. Any existing vSwitch, portgroup, and VMkernel information is removed. VMware recommends taking a screenshot of your network configuration from the vSphere Client or saving the output from the esxcfg-vswitch -l and esxcfg-vmknic -l commands before using this option.

In ESXi 6.x and above


To restore the Management vmkernel interface to the correct vmnic interface:
 

  • View the current vSwitch configuration and vmkernel interface configuration using these commands:

esxcli network vswitch standard list # list current vswitch configuration
esxcli network vswitch dvs vmware list # list Distributed Switch configuration
esxcli network ip interface list # list vmkernel interfaces and their configuration
esxcli network nic list # display listing of physical adapters and their link state

  • Add or remove network cards (known as vmnics) to or from a Standard vSwitch using these commands:
esxcli network vswitch standard uplink remove --uplink-name=vmnic --vswitch-name=vSwitch # unlink an uplink
esxcli network vswitch standard uplink add --uplink-name=vmnic --vswitch-name=vSwitch # add an uplink
  • Add or remove network cards (known as vmnics) to or from a vNetwork Distributed Switch (vDS) using these commands:

    esxcfg-vswitch -Q vmnic -V dvPort_ID_of_vmnic dvSwitch # unlink/remove a vDS uplink
    esxcfg-vswitch -P vmnic -V unused_dvPort_ID dvSwitch # add a vDS uplink


    Note: If connectivity was lost when migrating management networking to a Distributed Switch, it may be necessary to remove or disable the existing management vmkernel interface and recreate it in a Standard vSwitch port group with the same IP configuration.
     
  • On a vSphere Distributed Switch (vDS), delete an existing VMkernel port using this command:
esxcli network ip interface remove --interface-name=vmkX
Note: The vmk interface number used for management can be determined by running the esxcli network ip interface list command.
 
After the unreachable vmkernel port has been removed, it can be recreated on a Standard Switch.
  • View the default route on the esxi host.

    esxcfg-route -l or

    esxcli network ip route ipv4 list

 

  • To add the default route on the esxi host

          esxcfg-route  -a <default gateway ip>

  • After creating the vmkernel on the vSwitch, an appropriate tag can also be assigned to this vmkernel using following command.

    esxcli network ip interface tag add --interface-name=vmkX --tagname=name of tag

    add : Adds a tag on a given VMkernel network interface. Supported tags are : Management, VMotion, faultToleranceLogging,vSphereReplication, vSphereReplicationNFC, vSphereProvisioning, VSAN, VSANWitness, vSphereBackupNFC, PrecisionTimeProtocol, NVMeTCP, NVMeRDMA

    get : Gets the tags set on the given VMkernel network interface.

    remove : Removes a tag on a given VMkernel network interface.

     

    -i|--interface-name=<str> 
    The name of the VMkernel network interface on which tags should be set. This name must be an interface listed in the interface list command. (required)

    -t|--tagname=<str> 
    Tag name to assign to the interface (required)

  • If an existing Standard Switch does not exist, you can create a new one as well as a port-group to use with these commands:
esxcli network vswitch standard add --vswitch-name=vSwitch
esxcli network vswitch standard portgroup add --portgroup-name=portgroup --vswitch-name=vSwitch


Note: When creating a virtual switch, there are no linked vmnics by default. You will need to link vmnics as described earlier in this article. Additionally, follow Linux best practices when creating via CLI, avoiding special characters.
  • To set the MTU of a vSwitch/vmk to Jumbo Frames:
esxcfg-vswitch -m 9000 vswitch_name OR esxcli network vswitch standard set -m 9000 -v vswitch_name
esxcli network ip interface set -m 9000 -i vmkX
Note: If the VMkernel (VMK) interface, which is part of a vswitch, is configured to use Jumbo Frames, the vswitch it resides on must also be configured for Jumbo Frames.
  • To create a VMkernel port and attach it to a portgroup on a Standard vSwitch, run these commands:
esxcli network ip interface add --interface-name=vmkX --portgroup-name=portgroup
esxcli network ip interface ipv4 set --interface-name=vmkX --ipv4=ipaddress --netmask=netmask --type=static
Note: By default, the ESXi, the management vmkernel port is vmk0 and resides in a Standard Switch portgroup called Management Network.
  • If the vmnics associated with the management network are VLAN trunks, you may need to specify a VLAN ID for the management portgroup. To set or correct the VLAN ID required for management connectivity on a Standard vSwitch, run this command:
esxcli network vswitch standard portgroup set -p portgroup --vlan-id VLAN
  • It may be necessary to restart the host's management agents if network connectivity is not restored despite a correct configuration:
services.sh restart

 


Note: The command-line tool provides limited functionality when running the esxcfg-vswitch command with a vNetwork Distributed Switch. For example, you cannot create a dvportgroup or assign VLAN IDs to dvportgroups using this command. Some tasks must be completed from vCenter Server using the vSphere Client or vSphere Web Client.



Additional Information