Connecting or disconnecting a nic for a VM using ESXi command line
search cancel

Connecting or disconnecting a nic for a VM using ESXi command line

book

Article ID: 369138

calendar_today

Updated On:

Products

VMware vSphere ESXi 7.0 VMware vSphere ESXi 8.0

Issue/Introduction

Unable to manage a vm's nic being enabled or disabled from the GUI interface from host or vCenter 

Resolution

Use the following commands on the Node to determine if the network adapter is not connected and re-connect if needed.

 

  1. SSH to ESXi host as root
  2. List all VMs on the Node. Note the VMID of the VM you are trying to reach.
    vim-cmd vmsvc/getallvms

    Sample output

    Vmid   Name             File                                Guest OS                Version   Annotation
    541    test-windows     test-windows/test-windows.vmx       windows8Server64Guest   vmx-11
  3. Identify the device information. Verify that the network is connected. In this case, it is not.
    vim-cmd vmsvc/device.getdevices 541

    Sample output

    connectable = (vim.vm.device.VirtualDevice.ConnectInfo) 
                dynamicType = <unset>,
                startConnected = true,
                allowGuestControl = true,
                connected = false, <-----
                status = "ok",
  4. Find the DEVICEID for the NIC card that is connected to the local Network. (In this case the DEVICEID is for key 8235)
    (vim.vm.device.VirtualVmxnet3) {
             dynamicType = <unset>,
             key = 8235,
             deviceInfo = (vim.Description) {
                dynamicType = <unset>,
                label = "Network adapter 1",
                summary = "VM Network",
  5. From the above command, we can verify that the vNIC is connected = false.  This needs to be fixed, as follows.
    vim-cmd vmsvc/device.connection <Vmid from Step # 2> <DEVICEID = Key from Step # 4> <1 for enable / 0 for disable>

    Sample

    Enable the network:
    vim-cmd vmsvc/device.connection  541 8235 1
    
    Disable the network:
    vim-cmd vmsvc/device.connection  541 8235 0