Knowledge Base
The VMware Knowledge Base provides support solutions, error messages and troubleshooting guides

|
Configuring vSwitch or vNetwork Distributed Switch from the command line in ESXi/ESX (1008127)
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
Purpose
Resolution
- In ESX 4.0 Update 2, a new command-line tool, console-setup, was included to simplify the process of creating or restoring networking in the ESX service console. For more information, see Configuring or restoring networking from the ESX service console using console-setup (1022078).
- In ESXi 4.x and 5.x, 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). Note that 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 5.x:
Note: In ESXi 5.x, most of the legacy commands used in 4.x will continue to work. VMware recommends using their esxcli equivalents where possible as legacy esxcfg commands will be deprecated in a future release.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 uplin
Note: f 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 the following 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.Once the unreachable vmkernel port has been removed, it can be recreated on a Standard Switch.
- If an existing Standard Switch does not exist, you can create a new one as well as a port-group to use with the following 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.
- To create a VMkernel port and attach it to a portgroup on a Standard vSwitch, run the command:
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 the 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
In ESXi 3.x and 4.x:
To restore the Management vmkernel interface to the correct vmnic interface:- View the current vSwitch configuration and vmkernel interface configuration using the following commands:
esxcfg-vswitch -l # list current vswitch configuration
esxcfg-vmknic -l # list vmkernel interfaces and their configuration
esxcfg-nics -l # display listing of physical adapters and their link state
- These commands allow you to add or remove network cards (known as vmnics) to or from a Standard vSwitch:
esxcfg-vswitch -U vmnic vSwitch # unlink an uplink
esxcfg-vswitch -L vmnic vSwitch # add an uplink
- These commands allow you to add or remove network cards (known as vmnics) to or from a vNetwork Distributed Switch (vDS):
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
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 the following command:
esxcfg-vmknic -d -s DVswitchname -v virtual_port_ID
Note: The virtual port ID and Dvswitchname can be obtained using the esxcfg-vswitch -l command.
- Once the unreachable vmkernel port has been removed, it can be recreated on a Standard Switch. If an existing Standard Switch does not exist, you can create a new one as well as a port-group to use with the following commands:
esxcfg-vswitch -a vSwitch
esxcfg-vswitch -A portgroup 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.
- To create a VMkernel port and attach it to a portgroup on a Standard vSwitch, run the command:
esxcfg-vmknic -a -i IP_address -n netmask -p portgroup
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 the command:
esxcfg-vswitch -v VLANID -p portgroup vSwitch
- It may be necessary to restart the host's management agents if network connectivity is not restored despite a correct configuration:
services.sh restart
In ESX 3.x and 4.x:
Note: ESX uses a service console interface for management networking connectivity and does not utilize a vmkernel port for this purpose like ESXi. As such, the esxcfg-vswif command applies only to ESX.To restore the Management vmkernel interface to the correct vmnic interface:
- View the current vSwitch configuration and vmkernel interface configuration using the following commands:
esxcfg-vswitch -l # list current vswitch configuration
esxcfg-vmknic -l # list vmkernel interfaces and their configuration
esxcfg-nics -l # display listing of physical adapters and their link state
- These commands allow you to add or remove network cards (known as vmnics) to or from a Standard vSwitch:
esxcfg-vswitch -U vmnic vSwitch # unlink an uplink
esxcfg-vswitch -L vmnic vSwitch # add an uplink
- These commands allow you to add or remove network cards (known as vmnics) to or from a vNetwork Distributed Switch (vDS):
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
If connectivity was lost when migrating management networking to a vSphere Distributed Switch, it may be necessary to remove or disable the existing service console interface and recreate it in a Standard vSwitch port group with the same IP configuration.
- On a vSphere Distributed Switch (vDS), delete an existing service console port using the following command:
esxcfg-vswif -d -V DVSwitch_Name -P DVPort_ID vswifX
Note: The virtual port ID and Dvswitchname can be obtained using the esxcfg-vswitch -l command.
- Once the unreachable vmkernel port has been removed, it can be recreated on a Standard Switch. If an existing Standard Switch does not exist, you can create a new one as well as a port-group to use with the following commands:
esxcfg-vswitch -a vSwitch
esxcfg-vswitch -A portgroup 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.
- To create a service console port and attach it to a portgroup on a Standard vSwitch, run the command:
esxcfg-vswif -a -i ipaddress -n netmask -p portgroup vswif0
Note: By default, the ESX service console port is vswif0 and resides in a Standard Switch port group called Service Console.
- 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 the command:
esxcfg-vswitch -v VLANID -p portgroup vSwitch
- It may be necessary to restart the host's management agents if network connectivity is not restored despite a correct configuration:
service network restart
For ESXi 4.x and 5.x commands, see the vSphere Command-Line Interface Installation and Scripting Guide.
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 using the vSphere Client or vSphere Web Client.
Additional Information
Tags
See Also
- Configuring networking from the ESX service console command line
- Configuring a VLAN on a portgroup
- Configuring or restoring networking from the ESX service console using console-setup
- Como configurar o vSwitch ou switch distribuído de vNetwork a partir da linha de comando no ESXi/ESX
This Article Replaces
Update History
Request a Product Feature
To request a new product feature or to provide feedback on a VMware product, please visit the Request a Product Feature page.
Actions
KB:
- Updated:
- Categories:
- Languages:
- Product Family:
- Product(s):
- Product Version(s):

