VMware vSphere ESXi
All of the below commands can be run in an SSH session with the host, or from the DCUI shell console:
esxcfg-vswitch -l # list all current virtual switch information
esxcli network vswitch standard list # list current standard 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
Note: When creating a virtual switch, there are no linked vmnics by default, thus they will need to be linked using the commands described below. Additionally, follow Linux best practices when creating/modifying entities via CLI, for example avoiding special characters or spaces whenever possible.
esxcli network vswitch standard add --vswitch-name=vSwitch
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
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
esxcfg-vswitch -m 9000 vswitch_name or
esxcli network vswitch standard set -m 9000 -v vswitch_name
esxcli network vswitch standard portgroup add --portgroup-name=portgroup --vswitch-name=vSwitch
esxcli network vswitch standard portgroup set --portgroup-name=portgroup --vlan-id VLAN
Note: If only one NIC is being moved to the Standard vSwitch/portgroup then an alternative would be to remove the NIC from the port channel on the physical switch. E.g. if vmnic0 and vmnic1 are in a port channel with each other but only vmnic0 is being added to the Standard vSwitch temporarily then vmnic0 can be removed from the port channel on the physical switch and nothing would need to be changed from an ESXi perspective.
esxcli network vswitch standard policy failover set -l iphash -v vswitch_name
esxcfg-vmknic -l or
esxcli network ip interface list # view vmkernel adapter information
esxcli network ip interface tag get --interface-name=vmkX # get the services that are tagged on the vmkernel adapter, such as Management or vMotion
esxcli network ip interface remove --interface-name=vmkX # remove vmkernel adapter
esxcli network ip interface add --interface-name=vmkX --portgroup-name=portgroup # create vmkernel adapter
Note: The value must be a valid IPv4 address. If no gateway IP is provided, the gateway IP would be reset to "0.0.0.0" and need to be set before communication can occur
esxcli network ip interface ipv4 set --interface-name=vmkX --ipv4=ipaddress --netmask=netmask -g=gatewayip --type=static # configure existing vmkernel adapter networking information
esxcli network ip interface tag add --interface-name=vmkX --tagname=tag # add a tag to a vmkernel adapter
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
Note: If there is no vmkernel adapter already tagged for Management services, then Management will automatically be tagged on the newly-created adapter
remove
: Removes a tag on a given VMkernel network interface.
Note: If the VMkernel (VMK) interface, which is part of a vSwitch, is configured to use Jumbo Frames (i.e. any MTU value over 1500) then the vSwitch it resides on must also be configured for Jumbo Frames as well. The command to adjust the MTU for a Standard vSwitch is listed above.
esxcli network ip interface set -m 9000 -i vmkX
esxcfg-route -l or
esxcli network ip route ipv4 list # list the default routes on the host
esxcfg-route -a <default gateway ip> # add a static route to the host's routing table
services.sh restart
Notes: