In this post, I will show you why and how to use a new feature in Windows Server 2016 (WS2016) that is called Network Device Naming. You can name your virtual NICs in the settings of the virtual machine and retrieve or use that name in the guest OS.
Most of the time, a virtual machine will have a single virtual NIC that is connected to a virtual switch or network. In turn, it is connected to a team of physical NICs in the host. On rare occasions, you need to add more than one NIC to a virtual machine:
Adding NICs to Hyper-V virtual machines is easy. It is even easier with hot-add support in WS2016 but this can create some problems. Let’s say you build a virtual machine with 3 virtual NICs. You install or attach a guest OS to that virtual machine. What will the NICs be called in the guest OS? One might think, “NIC1 will be Ethernet1. NIC2 will be Ethernet2.” That thinking would be wrong. As always, Windows approaches plug and play in a random manner. There is no reliable link between the ordering of the NICs in the virtual machine configuration and the naming of the NICs in the guest OS.
The old way that we identified the virtual machine NIC was connected to the interface in the guest OS:
Unfortunately, this method is slow, not automatable for large deployments, and assumes that the guest OS admin will have sufficient rights to edit the virtual machine settings.
Microsoft already gave us a way to associate interface names with their PCI slot location in Windows Server 2012 (WS2012). Do we need anything else? Consistent device naming (CDN) was added in WS2012. It only works on some physical servers, where device naming is enabled. CDN does nothing for the aforementioned virtual machine scenarios because CDN works at the physical layer.
Hopefully, you read my networking chapter in a past book on WS2012 Hyper-V. We do not have to use the meaningless default of Network Adapter. The chapter discusses how PowerShell made it possible to create a NIC in a virtual machine with a user-friendly name. We can do that on WS2016 using the following cmdlet:
New-VMNetworkAdapter -Vmname “VM5” -Name “Storage 1”
We can go one step further on WS2016 by passing the name of the NIC into the guest OS. It can be retrieved from there. You can make this possible by adding an extra parameter to the above command:
New-VMNetworkAdapter -Vmname “VM5” -Name “Storage 1” -DeviceNaming ON
When you log into the virtual machine, you will find that the Storage 1 NIC is still using one of the meaningless Ethernet names. We can find the Ethernet NIC named Storage 1 and rename it.
If you want to do it manually, open up the properties of the NIC in Control Panel in the guest OS. Click the Configure button, browse to the Advanced tab, and look for a setting called Hyper-V Network Adapter Name.
If you want to use PowerShell, then you can run the following:
(Get-NetAdapterAdvancedProperty -Name “Ethernet” -RegistryKeyword HyperVNetworkAdapterName).DisplayValue