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:
- Getting Started
- Connecting to vCenter
- Starting VMs
- Stopping VMs
- Creating VMs
- Adding CPU's
- Adding Memory
- Retrieving IP Addresses
- Copying files with Copy-VMGuestFile
- Setting limits
- Enabling SSH
- Christmas Special
- Configuring vSphere MTU Size
- 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