PowerShell Friday: Configuring vSphere MTU Size
Several vSphere components can benefit from using a larger network frame size (MTU) than the regular size of 1500 bytes. vMotion, Storage: NFS, iSCSI and VSAN are examples that would gain some performance by increasing the frame size. In most cases, you would configure the MTU to a jumbo frame size, which is 9000.
Configuring the MTU size throughout your infrastructure can be tedious though, as you need to make sure you configure the entire chain of the network flow. If you’re not using Host Profiles for your ESXi host configuration, you have to make sure that you configure the involved vSwitches (standard and/or distributed) and the VMKernel PortGroups that need the larger size MTU. Forget this and you can have operational issues.
Having to configure the MTU size on several ESXi hosts which have standard vSwitches for their storage, vMotion or other functionality that you want to jumbo frames, is a repetitive task and it can take a while. We wouldn’t be system admins if we wouldn’t try to automate all the things that take time from us; so lets take a look at some PowerShell functions that can help you with configuring the MTU size.
You can configure the MTU size of a standard vSwitch with this small snippet:
$vswitch = Get-VirtualSwitch -Name vSwitch0 -VMHost (Get-VMHost -Name esxi01.lab.local)
Set-VirtualSwitch $vswitch -Mtu 9000
The first line retrieves the object for vSwitch0 on ESXi host esxi01.lab.local. The second line uses that vSwitch object to configure the MTU size.
The VDS can be configured in a similar fashion as the standard vSwitch, with the exception that we need to use the VDS module in the PowerCLI framework:
$vswitch = Get-VDSwitch -Name dvSwitch
Set-VDSwitch $vswitch -Mtu 9000
Here the first line imports the VDS module, which we need before the second line can be executed. The second line gets the object of the Distributed vSwitch named dvSwitch and the third line uses that object to configure the MTU size on the VDS.
Lastly, the VMKernel PortGroup that you’re going to be using for Storage, vMotion or something else that needs jumbo frames.
$vmkernel = Get-VMHostNetworkAdapter -Name vmk0 -VMHost (Get-VMHost -Name esxi01.lab.local)
Set-VMHostNetworkAdapter -VirtualNic $vmkernel -Mtu 9000
Here, the first line looks for the VMKernel port that’s named vmk0 and is on the ESXi host esxi01.lab.local. The second line takes the vmkernel portgroup object and configuring the MTU on it to 9000.
Want it to be easier?
I also created a PowerShell script that puts these functions together in an easy to use package. It’s available on GitHub:
This script can set the MTU on all vSwitches and VMKernel PortGroups with a certain name inside a specific DRS Cluster. Easy use for changing the MTU size across a multitude of ESXi hosts.
Using it is pretty simple, here’s an example:
PowerCLI Z:\PowerShell> .\vSphere-Set-MTU.ps1 -vCenterServer vcenter.lab.local -MTU 9000 -vMotion $True -Cluster MyCluster
This will set the MTU size to 9000 of all vSwitches and VMKernel PortGroups where the names contain:
Please be sure your network and/or storage equipment already supports a MTU of 9000
Press enter to start!
Finding and configuring all Standard vSwitches..
- Configured Standard vSwitch 'vSwitch0' to MTU 9000
- Configured Standard vSwitch 'vSwitch1' to MTU 9000
Finding and configuring all Distributed vSwitches..
- Configured Distributed vSwitch 'dvSwitch' to MTU 9000
Finding and configuring VMKernel PortGroups..
- Configured interface 'vMotion' on 'esxi01.lab.local' to MTU 9000
- Configured interface 'vMotion' on 'esxi02.lab.local' to MTU 9000
- Configured interface 'test-vMotion' on 'esxi02.lab.local' to MTU 9000
More information is on GitHub!
Other articles in the series PowerShell Friday:
- PowerShell Friday: Getting Started with PowerShell and PowerCLI
- PowerShell Friday: Connecting to vCenter
- PowerShell Friday: Starting VMs
- PowerShell Friday: stopping VMs
- PowerShell Friday: Creating Virtual Machines
- PowerShell Friday: Snapshots
- PowerShell Friday: Adding CPU’s with PowerCLI
- PowerShell Friday: Adding Memory with PowerCLI
- PowerShell Friday: ExtensionData
- PowerShell Friday: Retrieving IP addresses for VMs
- PowerShell Friday: Copying files with Copy-VMGuestFile
- PowerShell Friday: Setting Reservations with PowerCLI
- PowerShell Friday: Enabling SSH with PowerCLI
- PowerShell Friday: Christmas Special
- PowerShell Friday: Configuring vSphere MTU Size
- PowerShell Friday: Load PowerCLI from your own script
- PowerShell Friday: Using the Cisco ACI API
- PowerShell Friday: Enabling SSH with PowerCLI by Anne Jan Elsinga
- VMware Fling – ESXi Mac Learning dvFilter by Anne Jan Elsinga
- PowerShell Friday: Connecting to vCenter by Anne Jan Elsinga
- What’s new in vSphere 6 vMotion Enhancements by Erik Scholten
- VMware Virtual SAN (vSAN) is available now! by Erik Scholten
With over 12 years of experience in designing and deploying datacenter environments on all layers, Martijn now works as a NSX Specialist at VMware Benelux.
He is a Cisco’s CCIE Datacenter, VMware VCIX-NV, VCP-DCV, VCP-CMA, VCAP-DCA, VCAP-DCD, VSP, VTSP, VMware vExpert (2015-2017) and Cisco Champion (2015-2017).