Hyper-V networking: MAC addresses, adapter names and VLANs
PowerShell commands to find the MAC address of a Hyper-V virtual machine's adapters, rename an adapter, and configure it as a VLAN trunk.
Infrastructure hyper-v network microsoft virtualizationContents
Hyper-V, the hypervisor built into Windows, has PowerShell cmdlets for most of the network settings of a virtual machine. Here are three I use often: finding an adapter’s MAC address, renaming an adapter, and setting VLANs on it.
Get the MAC address of an adapter
Get-VM <VMName> | Get-VMNetworkAdapter | Select Name,MacAddress,IPAddresses
This lists the name, MAC address and IP addresses of every network adapter of the virtual machine.
Rename an adapter
A VM with several adapters is easier to manage when each one has a meaningful name. Select the adapter by its MAC address and rename it:
Get-VM <VMName> | Get-VMNetworkAdapter | ?{$_.MacAddress -eq '<MACAddress>'} | Rename-VMNetworkAdapter -NewName '<NewName>'
Write the MAC address the way Hyper-V shows it in the previous command: twelve
hexadecimal characters with no separators, such as 00155D012A0B.
Set VLANs on an adapter
Virtual LANs (VLANs) split a network into separate broadcast domains. To let an adapter carry several VLANs, put it in trunk mode:
Set-VMNetworkAdapterVlan -VMName <VMName> -VMNetworkAdapterName "<AdapterName>" -Trunk -AllowedVlanIdList "<VLANList>" -NativeVlanId <NativeVLAN>
-Trunklets the adapter carry traffic from several VLANs.-AllowedVlanIdListis the list of VLANs allowed on the adapter, such as"10,20,30-40".-NativeVlanIdis the VLAN whose traffic is sent untagged.