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.

Contents

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>
  • -Trunk lets the adapter carry traffic from several VLANs.
  • -AllowedVlanIdList is the list of VLANs allowed on the adapter, such as "10,20,30-40".
  • -NativeVlanId is the VLAN whose traffic is sent untagged.

Reference

Join the discussion

Comments are hosted on comments.vciso.ch, a server I run myself. Nothing is loaded from it until you press the button below. Loading comments connects your browser to that server, and signing in with GitHub sets a cookie there. See the privacy page for details.

Type to search.

↑ ↓ to move, Enter to open, Esc to close