ESXCLI COmmands
common ESXi CLI commands
As VMware Consultant we can all manage the vSphere client GUI, but sometimes you have to troubleshoot to fix things. ESXi operating system consists of the VMkernel and distributed VM filesystem. The VMware vSphere command-line interface (CLI) is the pane of glass used to control the ESXi shell
Check the ESXi installation time:
Show the list of available iSCSI adapters:
Add a DNS search domain
#esxcli network ip dns search remove -d test.com
List all available namespaces with corresponding commands
#esxcli vm process list
Perform a soft shutdown a VM using the VM ID (identified from the previous command):
#esxcli vm process kill -w 1234 -t hard
Note: The default firewall policy is to drop traffic if the opposite rules are not set.
#esxcli vm process kill -w 1234 -t soft
Use this to forcibly stop a virtual machine.
List all running virtual machines on the system to see the World ID of the virtual machine that you want to stop.
Enable force autostart feature:
.Uplink of vSwitchPermalink
• d – disk adaptor
#esxcli systemccount list
List of available ESXCLI commands depends on the ESXi version.
· device – device manager commands
· fcoe – Fibre Channel over Ethernet commands
· hardware – commands for checking hardware properties and configuring hardware
As VMware Consultant we can all manage the vSphere client GUI, but sometimes you have to troubleshoot to fix things. ESXi operating system consists of the VMkernel and distributed VM filesystem. The VMware vSphere command-line interface (CLI) is the pane of glass used to control the ESXi shell
Check
the ESXi hostname:
#esxcli system hostname
get
Check
the version of ESXi installed on the host:
#esxcli system version
get
Check the ESXi installation time:
#esxcli system stats installtime get
View installed PCI devices
# esxcli
hardware pci list | more
Check
the amount of memory installed
#esxcli hardware memory get
Information about installed processors
#esxcli hardware cpu
list
Check
the SNMP configuration:
#esxcli system snmp get
Get
currently status of the host
#esxcli system maintenanceMode get
#esxcli system maintenanceMode get
Put
host in maintenance mode:
#esxcli system maintenanceMode set --enable no
#esxcli system maintenanceMode set --enable y
Exit maintenance mode:
#esxcli system maintenanceMode set --enable no
Shutdown the host:
#esxcli system shutdown poweroff
Restart
the host:
#esxcli system shutdown reboot
#esxcli system shutdown reboot
Set a delay and write a reason of
rebooting the host to be saved in system logs
#esxcli system shutdown reboot -d 60 -r “Installing patches”
Restart
ESXi management agents ( ESXi host daemon service) #/etc/init.d/hostd
restart
Restart ESXi management agents (vCenter Agent service) :
#services.sh restart
Storage commands
Restart ESXi management agents (vCenter Agent service) :
#/etc/init.d/vpxa restart
Restart all management agents on ESXi :
#services.sh restart
Storage commands
List
all mappings of VMFS flie system to disks:
#esxcli storage core devices list
View mappings of VMFS file systems to disk devices:
#esxcli storage vmfs extent list
List all storage devices attached to the host:
#esxcli storage core devices list
View mappings of VMFS file systems to disk devices:
#esxcli storage filesystem list
List all the iSCSI paths on the system:
#esxcli storage core
path list
Display
the list of mounted NFS shares:
#esxcli storage nfs list
Locate
the unique device name (see the screenshot below):
#esxcli storage core
device list
Command
to get the S.M.A.R.T. data of that disk device:
#esxcli storage core device smart get -d naa.50026b7267020435
Show the list of available iSCSI adapters:
#esxcli iscsi adapter list
Re-discover and re-scan iSCSI adapters:
#esxcli iscsi adapter
discovery rediscover -A adapter_name
#esxcli storage core adapter rescan -A adapter_name
Instead of -A adapter_name you can rescan all adapters by using the --all option
Network commands
List a#esxcli network nic down -n vmnic0
List a#esxcli network nic down -n vmnic0
#esxcli network nic up -n vmnic0
View the domain search settings:
#esxcli network ip dns
search list
Add a DNS search domain
#esxcli network ip dns search add -d test.com
Remove a DNS search domain
#esxcli network ip dns search remove -d test.com
Add
a DNS server IP address
esxcli network ip dns server add -s 100.171.204.4
Remove a DNS server IP address
esxcli network ip dns
server remove -s 100.171.204.4
View the DNS servers set in the network settings:
View the DNS servers set in the network settings:
#esxcli network ip dns server list
List virtual
switches and port groups:
#esxcli network vswitch
standard list
Show statistics for the vmnic0 network interface:
#esxcli network nic stats get -n vmnic0
Check the firewall status and rule settings:
#esxcli network firewall
get
#esxcli network firewall ruleset list
Commands to change the hostname
#esxcli system hostname
set --host=hostname
#esxcli system hostname set --fqdn=fqdn
List local users on ESXi host
#esxcli system account
list
Create local ESXi user
Create local ESXi user
#esxcli system account add -d="Description" -i="username" -p="password" -c="password"
Test
List
available commands with descriptions
#esxcli command getdetails
#esxcli command getdetails
List all available namespaces with corresponding commands
#esxcli esxcli command list
Check the list of running VMs on the host (displays with VM ID):
#esxcli vm process list
Perform a soft shutdown a VM using the VM ID (identified from the previous command):
#esxcli vm process kill -w 1234 -t soft
#Perforrm a hard shutdown a VM using the VM ID:
#esxcli vm process kill -w 1234 -t hard
Note: The default firewall policy is to drop traffic if the opposite rules are not set.
Disable
the firewall on an ESXi host for troubleshooting:
#esxcli network firewall set --enabled false
The
firewall must be enabled with the command:
# network firewall set --enabled true
The network namespace includes many commands. Only basic and the most popular of them are considered in the Network section of today’s blog post. It is possible to configure a high number of network parameters with esxcli, but would require a long walkthrough that is out of scope for today’s article.
VIB installation commands
List all VIB packages installed on the host:
# network firewall set --enabled true
It is recommended to have the ESXi firewall enabled for security reasons
The network namespace includes many commands. Only basic and the most popular of them are considered in the Network section of today’s blog post. It is possible to configure a high number of network parameters with esxcli, but would require a long walkthrough that is out of scope for today’s article.
VIB installation commands
List all VIB packages installed on the host:
#esxcli software vib list
List
all VIB packages from a specific vendor:
#esxcli software vib
list | grep vendor_name
Install a VIB package from VMFS volume:
Install a VIB package from VMFS volume:
#esxcli software vib install -d "/vmfs/volumes/datastore/directoryname/patchname.zip"
Process commands
Check the list of running VMs on the host (displays with VM ID):
Check the list of running VMs on the host (displays with VM ID):
#esxcli vm process list
Perform a soft shutdown a VM using the VM ID
#esxcli vm process kill -w 1234 -t soft
Perform
a hard shutdown a VM using the VM ID:
#vim-cmd vmsvc
To list all virtual machines run
#vim-cmd vmsvc/get.summary <ID>
#esxcli vm process kill -w 1234 -t hard
The basic command to control the virtual machines is
#vim-cmd vmsvc
To list all virtual machines run
#vim-cmd vmsvc/getallvms
To get a summary of the machine run (where <ID> is a number)
#vim-cmd vmsvc/get.summary <ID>
To
power on/power off/suspend a VM ru
vim-cmd vmsvc/power.on <ID>
vim-cmd vmsvc/power.on <ID>
vim-cmd vmsvc/power.off <ID>
vim-cmd
vmsvc/power.suspend <ID>
Stop VM via esxcliPermalink
Use this to forcibly stop a virtual machine.
List all running virtual machines on the system to see the World ID of the virtual machine that you want to stop.
#esxcli vm process list
Stop
the virtual machine by running the following command.
#esxcli vm process kill
--type <kill_type> --world-id <ID
Autostart
of VMPermalink
#vim-cmd vmsvc/getallvms
Get a list of virtual machine IDs:
#vim-cmd vmsvc/getallvms
Enable force autostart feature:
#vim-cmd hostsvc/autostartmanager/enable_autostart true
Now
check the VMs startup settings:
#vim-cmd hostsvc/autostartmanager/get_autostartseq
#vim-cmd hostsvc/autostartmanager/get_autostartseq
.Uplink of vSwitchPermalink
Debug/ diagnostic commands
Check and troubleshoot ESXi performance with ESXTOP:
ESXTOP output refreshes every 5 seconds, to change the view use the following keys:
• c – cpu
• d – disk adaptor
• i – interrupts
• m – memory
• n – network
• p – power management
• v – disk VM
Open
the ESXi DCUI from the console via ssh
#dcui
Convert
a thick provisioned virtual disk to a thin provisioned virtual disk by
using vmkfstools:
#vmkfstools -i /vmfs/volumes/vmfs_datastore/vm_name/thick_disk.vmdk -d thin /vmfs/volumes/vmfs_datastore/vm_name/new_thin_disk_name.vmdk
Open the interactive VMware console:
#vmkfstools -i /vmfs/volumes/vmfs_datastore/vm_name/thick_disk.vmdk -d thin /vmfs/volumes/vmfs_datastore/vm_name/new_thin_disk_name.vmdk
Open the interactive VMware console:
#Vsish
Show loaded vmkernel drivers:
#vmkload_mod –list
Check the settings of the swap partition:
Check the settings of the swap partition:
#esxcli sched swap system get
You can list users by using one of the following commands:
#esxcli systemccount list
cat /etc/passwd or less/etc/passwd
ESXCLI is a part of the ESXi shell, this is a CLI framework intended to manage a virtual infrastructure (ESXi components such as hardware, network, storage, etc.) and control ESXi itself on the low level. All ESXCLI commands must be run in the ESXi shell (console). Generally, ESXCLI is the command that has a wide list of subcommands called namespaces and their options. The ESXCLI command is present right after ESXi installation along with other ESXi shell commands. You can locate ESXCLI and explore the nature of ESXCLI after executing the following commands:
#which esxcli
#ls -l /sbin/esxcli
List of available ESXCLI commands depends on the ESXi version.
Hence, the list of top ESXCLI namespaces for ESXi 6.7 is as follows:
· device – device manager commands
· esxcli – commands related to ESXCLI itself
· fcoe – Fibre Channel over Ethernet commands
· graphics – VMware graphics commands
· hardware – commands for checking hardware properties and configuring hardware
· iscsi – VMware iSCSI commands
·
network – this namespace includes a wide range of
commands for managing general host network settings (such as the IP address,
DNS settings of an ESXi host, firewall) and virtual networking components such
as vSwitch, portgroups etc.
· nvme – managing extensions for VMware NVMe driver
·
rdma – commands for managing the remote direct memory
access protocol stack
· software – managing ESXi software images and packages for ESXi
· system – commands for configuring VMkernel system properties, the kernel core system and system services
· vsan – VMware vSAN commands
· list – show the list of objects available for the defined namespace (for example, esxcli hardware bootdevice list – list available boot devices)
· sched – commands used for configuring scheduling and VMkernel system propertierty
· software – managing ESXi software images and packages for ESXi
· storage – commands used to manage storage
· system – commands for configuring VMkernel system properties, the kernel core system and system services
· vm – some commands that can be used to control virtual machine operations
· vsan – VMware vSAN commands
The main commands appear as verbs indicating the same action
· list – show the list of objects available for the defined namespace (for example, esxcli hardware bootdevice list – list available boot devices)
· get – get the value of the defined setting or property (for instance, esxcli hardware clock get – check the time set)
·
set – set the necessary parameter manually (for
example, esxcli hardware clock set -y 2019 -s 00 – set the
year to 2019 and set the seconds to 00)
· load/unload – load/unload system configuration (esxcli network firewall load – load the firewall module and firewall settings stored in the configuration file)
esxcli network Commands
| Command | Description | Options Help |
|---|---|---|
| network diag ping | Send ICMP echo requests to network hosts. |
|
| network firewall get | Get the firewall status. |
|
| network firewall load | Load firewall module and rulesets configuration. |
|
| network firewall refresh | Load ruleset configuration for firewall. |
|
| network firewall set | Set firewall enabled status and default action. |
|
| network firewall unload | Allow unload firewall module. |
|
| network firewall ruleset list | List the rulesets in firewall. |
|
| network firewall ruleset set | Set firewall ruleset status (allowedAll flag and enabled status). |
|
| network firewall ruleset allowedip add | Add allowed ip address/range to the ruleset ruleset. |
|
| network firewall ruleset allowedip list | list allowed ip addresses for rulesets. |
|
| network firewall ruleset allowedip remove | Remove allowed ip address/range from the ruleset. |
|
| network firewall ruleset rule list | List the rules of each ruleset in firewall. |
|
| network ip get | Get global IP settings |
|
| network ip set | Update global IP settings |
|
| network ip connection list | List active TCP/IP connections |
|
| network ip dns search add | Add a search domain to the list of domains to be searched when trying to resolve an host name on the ESXi host. |
|
| network ip dns search list | List the search domains currently configured on the ESXi host in the order in which they will be used when searching. |
|
| network ip dns search remove | Remove a search domain from the list of domains to be searched when trying to resolve an host name on the ESXi host. |
|
| network ip dns server add | Add a new DNS server to the end of the list of DNS servers to use for this ESXi host. |
|
| network ip dns server list | Print a list of the DNS server currently configured on the system in the order in which they will be used. |
|
| network ip dns server remove | Remove a DNS server from the list of DNS servers to use for this ESXi host. |
|
| network ip interface add | Add a new VMkernel network interface. |
|
| network ip interface list | This command will list the VMkernel network interfaces currently known to the system. |
|
| network ip interface remove | Remove a VMkernel network interface from the ESXi host. A VMKernel network interface can be uniquely specified by --interface-name or --portgroup-name or --dvs-name/--dvport-id. i.e. Providing its name or its connection point are two ways to uniquely specify a VMKernel network interface. |
|
| network ip interface set | This command sets the enabled status and MTU size of a given IP interface |
|
| network ip interface ipv4 get | List the IPv4 addresses assigned to VMkernel network interfaces. |
|
| network ip interface ipv4 set | Configure IPv4 setting for a given VMkernel network interface. |
|
| network ip interface ipv4 address list | List the IPv4 addresses assigned to VMkernel network interfaces. |
|
| network ip interface ipv6 get | Get IPv6 settings for VMkernel network interfaces. This does not include the IPv6 addresses which can be found in the listipv6 command |
|
| network ip interface ipv6 set | Configure IPv6 settings for a given VMkernel network interface. |
|
| network ip interface ipv6 address add | Add a static IPv6 address to a given VMkernel network interface. |
|
| network ip interface ipv6 address list | This command will list all of the IPv6 addresses currently assigned to the system |
|
| network ip interface ipv6 address remove | Remove an IPv6 address from a given VMkernel network interface. |
|
| network ip interface tag add | Adds a tag on a given VMkernel network interface. Supported tags are: Management, VMotion, faultToleranceLogging, vSphereReplication, vSphereReplicationNFC, vSphereProvisioning, VSAN, VSANWitness |
|
| network ip interface tag get | Gets the tags set on the given VMkernel network interface. |
|
| network ip interface tag remove | Removes a tag on a given VMkernel network interface. |
|
| network ip ipsec sa add | Add a Security Association. |
|
| network ip ipsec sa list | List configured Security Associations |
|
| network ip ipsec sa remove | Operation to remove Security Association(s) |
|
| network ip ipsec sp add | Add a Security Policy. |
|
| network ip ipsec sp list | List configured Security Policys |
|
| network ip ipsec sp remove | Operation to remove Security Policy |
|
| network ip neighbor list | List ARP table entries |
|
| network ip neighbor remove | Remove ARP table entries |
|
| network ip netstack add | Add a new Netstack Instance. |
|
| network ip netstack get | Get runtime/configuration settings for a given Netstack Instance. |
|
| network ip netstack list | This command will list the VMkernel Netstack instances currently known to the system. |
|
| network ip netstack remove | Remove a new Netstack Instance. |
|
| network ip netstack set | Configure settings for a given Netstack Instance. |
|
| network ip route ipv4 add | Add IPv4 route to the VMkernel. |
|
| network ip route ipv4 list | List configured IPv4 routes |
|
| network ip route ipv4 remove | Remove IPv4 route |
|
| network ip route ipv6 add | Add IPv6 route to the VMkernel. |
|
| network ip route ipv6 list | List configured IPv6 routes |
|
| network ip route ipv6 remove | Remove IPv6 route from the VMkernel |
|
| network multicast group list | List all the multicast group members. |
|
| network nic down | Bring down the specified network device. |
|
| network nic get | Get the generic configuration of a network device |
|
| network nic list | This command will list the Physical NICs currently installed and loaded on the system. |
|
| network nic set | Set the general options for the specified ethernet device. |
|
| network nic up | Bring up the specified network device. |
|
| network nic coalesce get | Get coalesce parameters |
|
| network nic coalesce set | Set coalesce parameters on a nic |
|
| network nic coalesce high get | Get information about the behavior of a NIC when it sends or receives packets at high packet rate. |
|
| network nic coalesce high set | Set parameters to control the behavior of a NIC when it sends or receives packets at high packet rate. |
|
| network nic coalesce low get | Get information about the behavior of a NIC when it sends or receives packets at low packet rate. |
|
| network nic coalesce low set | Set parameters to control the behavior of a NIC when it sends or receives packets at low packet rate. |
|
| network nic cso get | Get checksum offload settings |
|
| network nic cso set | Set checksum offload settings on a nic |
|
| network nic eeprom change | Change EEPROM on a nic |
|
| network nic eeprom dump | Dump device EEPROM |
|
| network nic negotiate restart | Restart N-Way negotiation on a nic |
|
| network nic pauseParams list | List pause parameters of all NICs |
|
| network nic pauseParams set | Set pause parameters for a NIC |
|
| network nic queue count get | Get netqueue count on a nic |
|
| network nic queue count set | Set number of netqueues on a nic |
|
| network nic queue filterclass list | List the netqueue supported filterclass of all physical NICs currently installed and loaded on the system. |
|
| network nic queue loadbalancer list | List the netqueue load balancer settings of all physical NICs currently installed and loaded on the system. Setting legend as follows. S: Setting supported by device, U: Setting unsupported by device, N: Setting not applicable to device, A: Setting allowed at load balancing, D: Setting disallowed at load balancing. |
|
| network nic queue loadbalancer set | Enable/disable netqueue load balancer setting on a NIC. |
|
| network nic register dump | Dump device registers |
|
| network nic ring current get | Get current RX/TX ring buffer parameters of a NIC |
|
| network nic ring current set | Set current RX/TX ring buffer parameters of a NIC |
|
| network nic ring preset get | Get preset RX/TX ring buffer parameters of a NIC |
|
| network nic selftest run | Run self test |
|
| network nic sg get | Get scatter-gather settings |
|
| network nic sg set | Set scatter-gatter settings on a nic |
|
| network nic software list | List software simulation settings of all physical NICs currently installed and loaded on the system. |
|
| network nic software set | Enable and disable software simulation settings on a NIC. |
|
| network nic stats get | Get NIC statistics for a given interface. |
|
| network nic tso get | Get TCP segmentation offload settings |
|
| network nic tso set | Set TCP segmentation offload settings on a nic |
|
| network nic vlan stats get | List VLAN statistics for active VLAN's on the NIC. |
|
| network nic vlan stats set | Enable/disable VLAN statistics collection on the NIC. |
|
| network port filter stats get | Filter statistics for a given port. |
|
| network port stats get | Packet statistics for a given port. |
|
| network sriovnic list | This command will list the SRIOV Enabled NICs (PFs) currently installed and loaded on the system. |
|
| network sriovnic vf list | Get the generic configuration of VFs for SRIOV NIC. |
|
| network sriovnic vf stats | Get statistics for given VF of a SRIOV NIC. |
|
| network vm list | List networking information for the VM's that have active ports. |
|
| network vm port list | List of active ports for a given VM. |
|
| network vswitch dvs vmware list | List the VMware vSphere Distributed Switch currently configured on the ESXi host. |
|
| network vswitch dvs vmware lacp config get | Get LACP configuration on DVS |
|
| network vswitch dvs vmware lacp stats get | Get LACP stats on DVS uplinks |
|
| network vswitch dvs vmware lacp status get | Get LACP status on DVS |
|
| network vswitch dvs vmware lacp timeout set | Set long/short timeout for vmnics in one LACP LAG |
|
| network vswitch standard add | Add a new virtual switch to the ESXi networking system. |
|
| network vswitch standard list | List the virtual switches current on the ESXi host. |
|
| network vswitch standard remove | Remove a virtual switch from the ESXi networking system. |
|
| network vswitch standard set | This command sets the MTU size and CDP status of a given virtual switch. |
|
| network vswitch standard policy failover get | Get the failover policy settings governing the given virtual switch |
|
| network vswitch standard policy failover set | Configure the Failover policy for a virtual switch. |
|
| network vswitch standard policy security get | Get the Security Policy governing the given virtual switch. |
|
| network vswitch standard policy security set | Set the security policy for a given virtual switch |
|
| network vswitch standard policy shaping get | Get the shaping policy settings for the given virtual switch |
|
| network vswitch standard policy shaping set | Set the shaping policy settings for the given virtual switch |
|
| network vswitch standard portgroup add | Allows the addition of a standard port group to a virtual switch. |
|
| network vswitch standard portgroup list | List all of the port groups currently on the system. |
|
| network vswitch standard portgroup remove | Remove a port group from the given virtual switch |
|
| network vswitch standard portgroup set | Set the vlan id for the given port group |
|
| network vswitch standard portgroup policy failover get | Get the network failover policy settings governing the given port group |
|
| network vswitch standard portgroup policy failover set | Configure the Failover policy for a port group. These setting may potentially override virtual switch settings. |
|
| network vswitch standard portgroup policy security get | Get the Security Policy governing the given port group. |
|
| network vswitch standard portgroup policy security set | Set the security policy for a given port group |
|
| network vswitch standard portgroup policy shaping get | Get the network shaping policy settings governing the given port group |
|
| network vswitch standard portgroup policy shaping set | Set the shaping policy settings for the given port group |
|
| network vswitch standard uplink add | Add an uplink to the given virtual switch. Note if this virtual switch has a NIC teaming policy assigned to it then the policy must also be modified to enable use of this uplink on this virtual switch |
|
| network vswitch standard uplink remove | Remove an uplink from the given virtual switch. Note if this virtual switch has a NIC teaming policy assigned to it then the policy must also be modified to disable use of this uplink on this virtual switch |
|
Comments
Post a Comment