Removing Orphaned Distributed vSwitch from ESXi Hosts

Overview

When ESXi hosts were previously managed by a vCenter that has been removed, the distributed vSwitch (dvSwitch) configuration remains on the hosts as “orphaned” objects. This guide shows how to safely remove them.

WARNING

⚠️ CRITICAL: Removing network configuration can disconnect your host! Ensure you:

  • Have console access (or out-of-band management)
  • Know which vmnic is used for management network
  • Have a rollback plan

Method 1: Using vCenter (After Adding Hosts)

This is the SAFEST method if you’ve already added hosts to new vCenter:

1.1 Check Current Network Configuration

  1. In vCenter, select each host
  2. Go to ConfigureNetworkingVirtual switches
  3. Look for distributed switches with ⚠️ warning icons
  4. Note which vmnics are assigned to the orphaned dvSwitch

1.2 Migrate VMs to Standard Switch

  1. Create a temporary standard vSwitch:
    • Host → Configure → Virtual switches → Add standard switch
    • Name: vSwitch1 (or next available)
    • Add appropriate uplinks (vmnics)
  2. Create port groups on standard switch matching your needs:
    • VM Network
    • Management Network (if needed)
  3. Migrate any VMs using the orphaned dvSwitch

1.3 Remove Host from Orphaned dvSwitch

  1. Host → Configure → Networking → Virtual switches
  2. Find the orphaned distributed switch
  3. Click on it → Remove from distributed switch

Method 2: Using ESXi Command Line (Direct Method)

2.1 Connect to Each Host

ssh root@esxi-nuc-01.markalston.net

2.2 List All vSwitches

# List all virtual switches
esxcli network vswitch standard list
esxcli network vswitch dvs vmware list

# List all port groups
esxcli network vswitch standard portgroup list
esxcli network vswitch dvs vmware portgroup list

2.3 Check VMkernel Interfaces

# CRITICAL: Find management network
esxcli network ip interface list

# Note which vmk interface is used for management
esxcli network ip interface ipv4 get

2.4 List Physical NICs and Their Assignments

# See which vmnics are assigned where
esxcli network nic list
esxcli network vswitch standard list

# Check DVS uplinks
esxcfg-vswitch -l

2.5 Remove VMs from Distributed Port Groups

First, check if any VMs are using the DVS:

# List all VMs and their network connections
vim-cmd vmsvc/getallvms
vim-cmd vmsvc/get.networks [vmid]

2.6 Remove Host from Distributed vSwitch

# Get the DVS UUID
esxcli network vswitch dvs vmware list

# Remove host from DVS (replace with actual DVS name)
esxcli network vswitch dvs vmware remove -d [dvs-name]

Method 3: Nuclear Option - Reset Network Configuration

⚠️ LAST RESORT - Requires Console Access!

3.1 Via DCUI (Direct Console)

  1. Access host console (physical or IPMI/iLO)
  2. Press F2 to login
  3. Navigate to Network Restore Options
  4. Select Restore Standard vSwitch
  5. Confirm - this creates a simple vSwitch0 with management

3.2 Via Command Line

# Reset to default networking (DANGEROUS - console access required!)
esxcli network vswitch standard policy security set --allow-promiscuous false --allow-mac-change false --allow-forged-transmits false --vswitch-name vSwitch0

# Recreate basic management network
esxcli network vswitch standard add --vswitch-name vSwitch0
esxcli network vswitch standard uplink add --uplink-name vmnic0 --vswitch-name vSwitch0
esxcli network vswitch standard portgroup add --portgroup-name "Management Network" --vswitch-name vSwitch0

Step 1: Document Current Configuration

On each host, run:

# Save current network config
esxcfg-vswitch -l > /tmp/network-config-backup.txt
esxcli network vswitch dvs vmware list > /tmp/dvs-config.txt
esxcli network ip interface list > /tmp/vmk-interfaces.txt

# Check what's using the DVS
esxcfg-vswitch -l | grep -A5 -B5 "DVS"

Step 2: Create Standard vSwitch First

Before removing DVS, ensure you have working standard switches:

# Check existing standard switches
esxcli network vswitch standard list

# If vSwitch0 exists and has your management vmk, you're safe
# If not, create one with spare vmnic first

Step 3: Remove Orphaned DVS

Option A: From vCenter (Safest)

  • Add hosts to new vCenter first
  • Use GUI to remove from distributed switch

Option B: From CLI (If needed)

# List DVS
esxcli network vswitch dvs vmware list

# Remove (replace 'dvs-name' with actual name)
esxcli network vswitch dvs vmware remove -d dvs-name

Verification Commands

After removal, verify:

# Check no DVS remains
esxcli network vswitch dvs vmware list

# Verify standard switches are working
esxcli network vswitch standard list

# Confirm management network is accessible
esxcli network ip interface list

# Check all vmnics are accounted for
esxcli network nic list

Recovery Plan

If you lose network access:

  1. Console Access: Use DCUI to restore network
  2. From vCenter: If hosts are in vCenter, can reconfigure from there
  3. Reboot: Sometimes a reboot clears orphaned objects

Your Next Steps

  1. Check current state on one host first:
    ssh root@esxi-nuc-01.markalston.net
    esxcfg-vswitch -l
    
  2. Identify the orphaned DVS name

  3. Ensure management network is on standard vSwitch

  4. Remove DVS using preferred method

  5. Repeat for other hosts

Remember: The management network is critical - don’t remove any switch that has your management vmkernel interface!


This project is for educational and home lab purposes.