Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Hyper-V Virtual Switches

Virtual Machines communicate over one or more simulated wired Ethernet networks. Wired networks are physically created by running an Ethernet cable from the Ethernet port of devices to an available port on an Ethernet switch. Switches receive packets of data from any device, examine the six-byte destination ID field, and then either forward the packet to the destination device or else send the packet out every port to all connected devices. Any port on one switch can be connected to any port on another switch to extend the network.

Hyper-V creates one or more virtual Ethernet adapters in each virtual machine. Microsoft has written drivers for this Hyper-V adapter for Windows and Linux, and other systems like freeBSD also support this device. An application sends data on the network. In the Kernel, the data is broken up into TCP packets, which are then inserted into IP packets, which are then inserted into Ethernet packets. By default, Ethernet packets begin with the 6-byte destination device ID and are no larger than 1500 bytes. When one VM sends data to another VM, or to the host Windows system, Hyper-V simply has to copy the data from the sending buffer of the one virtual machine to an empty receive buffer in the destination. Moving data from one real memory location to another is just program code.

When data is being sent out a physical Ethernet adapter, then there are additional layers of processing. A physical device can be on the motherboard, on an adapter card, or out on a USB device. It can use Intel, Realtek, or other chips. The network can run at many speeds, and WiFi and Bluetooth are other types of network adapters.

All Virtual Machine systems (Oracle VirtualBox, VMware, Linux KVM) will create one or more named “virtual networks” and configure virtual network adapters on virtual machines to be “connected” to these networks. They can all associate a physical network adapter with each named network.

Hyper-V does the same thing, but it chooses to define a named virtual network as a “virtual switch”. This is a metaphor that someone thinks will be helpful to end users. Connecting a virtual machine to a virtual switch is logically the same as plugging an Ethernet cable into a physical device and a physical switch. However, there is no Hyper-V component that behaves in the same way as the firmware in a real switch. Hyper-V moves data directly between VMs or between a VM and the Kernel of the host Windows system. To do this, Hyper-V maintains a table of the 6-byte ID used by each virtual adapter so it can determine from the destination field in the packet just where the data is to be sent.

You can add one physical Ethernet adapter in the Windows host operating system to a Hyper-V virtual switch. If the adapter is no longer going to be used by the host system, then Windows disables all the higher-level layers that convert wrap data into TCP, then IP, and then Ethernet packets. It just keeps the lower layers that take the Ethernet packet and send it to the chip, card, or USB device. When a VM generates an Ethernet packet that has a 6-byte destination that is not associated with any other VM, Hyper-V moves the data from the VM transmit buffer to a transmit buffer for the physical device in the host Windows Kernel and the Ethernet packet goes out to the physical network for delivery.

If the host Windows system wants to share a physical Ethernet device with a Hyper-V virtual switch, then the device is split into what appears to be two network adapters. One network adapter is essentially a host side version of the Hyper-V driver installed in Virtual Machines, and it handles the upper layers of the network protocol (application data to TCP packet to IP packet to Ethernet frame). The other device has the lower levels of the protocol that take an Ethernet packet and send it to the chip or card so it goes out on the network. Then, just like the drivers in the VMs, this host virtual adapter turns the Ethernet packet over to Hyper-V to determine whether the 6-byte destination in the packet is a virtual adapter in one of the VMs. If not, then Hyper-V moves the data to the transmit buffer of the physical network adapter.

Every driver of a physical network adapter has configuration and tuning options. For convenience, these options appear to be associated with both of the two network devices that the physical adapter was split into.

The NAT Gateway Option

When you share a physical network adapter with VMs, then each VM appears to the network as a separate computer. You can do this at home, or in a lab, or if you have more than one computer at your desk. However, the Yale network does not expect multiple computers to be sharing a desktop network port, and sharing does not work for WiFi adapters.

The alternative is to turn the host Windows system into what is called a “gateway” device. The “wireless router” that connects your home network to your Internet service provider is really a gateway.

Gateways use Network Address Translation (NAT) to rewrite the TCP and IP packets sent from other computers so that the packet appears to be coming from an application inside the gateway device. In this case, NAT takes all the Internet traffic from the VMs inside your computer and makes it look like it was coming from Windows applications running on the laptop.

In this case, you do not associate any physical adapter to any Hyper-V switch. All the Hyper-V networks are pure virtual. Either by manual configuration or through DHCP the VMs are given a network configuration with a “gateway IP address” pointing to a virtual Hyper-V adapter on the host Windows system. Windows then has to be configured to expect that traffic arriving from that virtual adapter must be processed through NAT and then forwarded to the Yale network or Internet.

The Default Network

Hyper-V creates one initial virtual switch/network called Default. Microsoft got tired of end users screwing up their Hyper-V networking and calling for support, so if a VM is connected to the Default network and turns on automatic configuration of network parameters (DHCP), then the VM will get access to the Internet as long as the host computer has network access.

However, to create a network that the user cannot screw up, Default assigns itself new IP addresses every time your machine boots up. So machines on the Default network have no fixed IP address you can connect to. You can reference a VM by appending “.local” to the hostname. If you are sane, the hostname will also be the VMName so you don’t get confused, but you have to rename the machine during or after the OS is installed.

In detail

  • There is no configuration or administration of Default.

  • When the host system boots up, Default gets a “factory reset” and chooses a random subnet range of addresses.

  • There is a virtual Ethernet adapter on the host Windows system attached to Default and assigned the first IP address in the subnet range.

  • Default uses DHCP to assign new IP addresses to each virtual adapter on a VM that is attached to it. It also sets the host virtual adapter address as the gateway and DNS server address for VMs.

  • The host Windows system provides a gateway service using the NAT protocol. When a client program on a VM connects to an Internet service, it passes the request to the host Windows system. The NAT function changes the request so it appears to be coming from a program on the host physical computer, and then sends the data out in the same way it would send data for a local application program. It will use wired, or WiFi, or VPN for this data in exactly the same way as it sends data from Firefox or Outlook.

  • When a VM gets an IP address from DHCP, the host Windows system writes the VM hostname (with a dummy domain suffix of *.mshome.net) and IP address in the file C:\Windows\System32\drivers\etc\hosts.ics. This is treated as an extension of the normal “hosts” file on every Windows or Linux system. When Windows is looking for a computer name, it checks the hosts files first before going to a DNS server. Therefore, if there is a VM named “docker” then the host can communicate to it using the dummy name of “docker.mshome.net”.

  • The VMs also get a dummy DNS server from the host. When they ask for the IP address associated with a name, then host OS looks the name up using its own standard API. This checks the hosts files first, then makes a DNS request if the name is not in the file. Therefore, the VMs get the same DNS server the host Windows system provides and can find each other using vmname.mshome.net.

Default provides so many useful services that you will probably want to connect it to all your VMs. However, there are a few things it does not do.

  • You cannot assign static IP addresses on Default.

  • External clients cannot access VM services through Default.

  • You cannot connect Default to a physical adapter card.

  • Default only supports local VMs running on your physical host computer.

Therefore, a technically sophisticated user with more complex network requirements may want to create additional virtual switches with other characteristics and additional virtual adapters for specific VMs to attach them to these custom networks.

The Virtual Switch

A virtual switch is a concept for Hyper-V configuration.

Data does not move from the VM to some Hyper-V “switch” memory, get processed by some simulated “switch” firmware, and then get forwarded to another VM. Rather when a virtual Ethernet adapter is ready to transmit data to the network, Hyper-V determines what other virtual adapters are connected to the same virtual switch and moves the data from the memory of one VM directly to the memory of the other VM.

In a real network physical switches are connected to each other and forward data from switch to switch to switch. This is the one thing you cannot do with a Hyper-V virtual switch. By analogy, each virtual switch is a dead end street. You can send data outside through a gateway NAT function provided by the Host or by a VM with gateway/router/firewall software, or you can create a connection to an external real network through a single physical Ethernet adapter connected to a real network. You cannot “bridge” one virtual switch to another, even using “bridge” software on a VM connected to both switches.

Hyper-V Manager Switch Types

The Microsoft Hyper-V Managers utility give three names to specific configurations and if you use the GUI you have to choose one of the names. The Powershell commands, however, allow you to add or remove physical LAN adapters and a virtual host LAN adapter to existing switches without regard to these limited names. In reality there are four possibilities and two ways to use the fourth option:

Hyper-V “Private” - A virtual switch that is neither connected to a LAN adapter or to the host operating system is “private”. You connect VMs to it and they can talk to each other. Since this would leave the VMs unable to update themselves if it were the only network they have, you typically connect at least one of the VMs to another switch that is connected out and have that VM serve as a NAT gateway or router for the other VMs.

Hyper-V “Internal” - A virtual switch that is connected to the Windows 10 host (through a Hyper-V virtual LAN) can provide the VMs with some type of protected client access to the real network and internet if the Windows 10 host will provide the router function. Any Windows 10 system can provide a NAT gateway using the Powershell New-NetNAT command, but Windows 10 doesn’t have a DHCP service. So either you have to configure static addresses for each VM, or you need one of the VMs to provide DHCP to all the other VMs (and make sure that VM is running all the time).

Hyper-V “External” (special case) - If you only connect a spare unused physical LAN adapter on your host computer to the virtual switch and you don’t connect the host to that switch, then you can physically connect the VMs directly to the real network without going through the host OS. Each VM can have its own network address just like real computers on the physical network. The host can talk to them, but through the external network as if they were other real computers and not internal VMs. Typically this requires the host to have two LAN adapters. Of course, many people connect their laptop to the WiFi and they have a spare wired Ethernet port they aren’t using, but if that is not the case you can get an adapter card for a desktop or a USB Network Adapter for a laptop.

Hyper-V “External” Bridge - This is the more common configuration where you connect both a physical host LAN adapter and a virtual host LAN adapter to the same switch. Normally you ask the Hyper-V Manager to create both types of connections at the same time. After a brief break in network connectivity, the host OS still has a wired connection to the same network with the same network address as before. Now, however, it can share that LAN adapter and cable with the VMs connected to the switch. They also appear to be on the physical network, get the same type of network address that the host had, can talk to other computers on the network, and can share files and provide services to other computers.

Hyper-V “External” (physical private VM network) - The last type is something like the previous special case because you associate the virtual switch with a spare LAN adapter, but in this case you do not connect that adapter to the public network. You can connect it to a cable that runs between two computers, or to a private switch not connected to the internet. You may do most of your work on a laptop, but laptops are not powerful machines. You can use this to connect your laptop privately to a more powerful desktop workstation. Run Hyper-V on both the laptop and the desktop and the laptop host system you normally use where all your tools and files reside is not only able to talk to its own VMs but also to the VMs created by the connected desktop. Again you have to solve the problem of creating a gateway or router on either the laptop or the desktop so the VMs can install software and get updates from the internet.

Splitting the Physical Network Adapter

If you start out with a physical Network Adapter that is configured to the host OS, and you then associate it with a Hyper-V virtual switch, the configuration of the Network Adapter splits in half. On the host Windows 10 system, you start with one Network adapter and end up with two.

One network adapter on the host system represents the physical device that is now being shared with the VMs. If you look at it in Device Manager, it still has all the parameters associated with firmware (except for the Ethernet hardware address). If you want to allow Jumbo Frames, this is the device that manages those options.

A new Virtual Ethernet Adapter has been created in the Host Windows 10 system which gets the Ethernet Hardware (MAC) Address from the adapter and also all the higher level network drivers, especially the IPv4 and IPv6 configuration options. This is because the Host Windows 10 system must have its own addresses, both at the Ethernet level and at the Internet level. Other VMs will also be connected to the switch, and each will have its virtual Network Adapter with its own Ethernet hardware address and its own IPv4 and IPv6 configurations separate from the host.

Code Block
Name                      InterfaceDescription                    ifIndex Status MacAddress  
Ethernet                  Marvell AQtion 10Gbit Network Adapter        15 Up     70-85-C2-C7-BF-6E
vEthernet (Bridge)        Hyper-V Virtual Ethernet Adapter #3          13 Up     70-85-C2-C7-BF-6E

Here a Marvell AQtion 10Gbit adapter card has been shared with a Hyper-V virtual switch named “Bridge”. It has generated two Network Adapter entries. The first represents the card itself, while the second contains all the addresses that the host uses to send and receive data. Each VM attached to the switch will have its own distinct addresses. Data from the host and the VMs will go through the one adapter card to whatever physical switch the adapter is connected to.

VLANs

As mentioned above, you can spend $15 to buy a simple 8 port switch or $20 to buy a “smart switch” that supports VLANs. Corporations like Yale use VLANs to partition the campus network up into groups of devices for security or traffic management. Home users may want a VLAN to separate their Internet of Trash devices from work devices, but you can do that by physically separating the two, especially since the IOT is wireless and the work devices can connect to each other wired.

So despite what the letters “VLAN” stand for, in Hyper-V Virtual Machine networks the most interesting use of VLAN configuration is to give a Virtual Machine a physical network port (it is an anti-virtual trick turning virtual stuff into real hardware).

You spend $20 for 8 ports or $40 for a 16 port smart switch. You create a Bridge virtual switch on your host computer and connect the adapter you assign to it to one of the ports on the smart switch. If you have more than one host running VMs, you may want to connect each of them to a port on the switch. If you want to use this to access the internet you need another port to provide a connection to the gateway or to a firewall through which you can get to the gateway.

Now in a quick oversimplified version of the configuration, you read the manual on the switch, connect a browser and sign into the web based administration tool that runs in the switch, and assign a VLAN ID number to a set of empty ports. The number is arbitrary, so lets assume you assign individual VLAN IDs 11, 12, …, 16 to six currently empty ports on the switch. Ports can be assigned to multiple VLAN IDs if they are “tagged”, and you do this to the ports where you just connected the Bridge physical adapter from the host computers and you make them part of all six VLAN IDs (in this example, and more if you get a bigger switch).

Now in the Hyper-V Manager you can display the configuration of each Virtual Machines and click on the configuration of the virtual LAN adapter connected to this Bridge switch.

...

You can click the check box for Enable virtual LAN identifier and then in the text box below it type in one the the IDs you assigned to the smart switch ports (11 to 16 in this example).

If one VM is assigned to VLAN ID 14 and one port on the smart switch is assigned VLAN ID 14, then this physical port on the smart switch has become essentially a physical representation of what would have been the LAN adapter jack on the back of the physical computer if the VM has been magically turned into a real physical box. You can plug in a wire to that port and it is directly connected to this virtual adapter on this VM.

...

The Internet Stack

Every application program interacts with the Internet through a programming interface provided by the Operating System Kernel known as the Socket API originally defined by UC Berkeley in its BSD Unix system. A client program can specify one network adapter by its IP address or let the operating system choose the best available adapter. It specifies the other end (the server) by an IP address (determined by looking up the name in DNS) and the port number of a service (such as 443 for the Web https: protocol). A connection is established between the client and server through the internet. Each end then sends data by presenting varying length blocks of bytes which are treated as a continuous stream of bytes delivered to the other end.

The Socket API is presented to programs by the operating system Kernel. Within the Kernel there are steps in the processing of the data traditionally referred to as Layers.

TCP is responsible for ensuring that the data is received by the other end and recovering if some data is corrupted or lost somewhere in the Internet. It maintains a count of bytes sent from one end and a count of bytes successfully received at the other end. The sender must maintain a copy of bytes sent but not yet acknowledged (the “window” of data in transit) so that lost data can be retransmitted until it is successfully received. Data sent is preceded by a “TCP header” with the number assigned to the first byte of data being sent or acknowledged and the port number associated with the program that is the client or server at each end.

IP is responsible for routing data through the internet from the sending computer to the receiving computer. An IP Header containing the IP address of the sender and destination is placed in front of packets containing the TCP Header and program data.

Ethernet is responsible for sending the IP packet from a computer to the router/gateway device that connects each computer to the corporate or campus network or to the network of your Internet Service Provider. Except in special cases, the maximum size of an Ethernet packet is around 1500 bytes. Each LAN adapter has a 6-byte Ethernet ID number, and each packet on the network has an Ethernet Header with the 6-byte ID of the sending adapter and the destination adapter.

The original Ethernet hardware is no longer used, but today the Ethernet standard is emulated by adapters that connect to wires, fiber optic cables, cable TV, WiFi, Bluetooth, the 5G cellphone network, or to Starlink satellites. There are obviously vastly different types of equipment to connect to all these different types of transmission, but the operation to “send this 1500 byte Ethernet packet on the network” is universal and is, therefore, the way that all the different types of networks communicate with each other through gateway modem and router boxes.

Virtual Networks

A Virtual Machine behaves as if it were a computer. It runs an operating system and presents to that OS the appearance of one or more Ethernet network adapters. To simplify things, a VM only sees a simple wired LAN adapter, like the wired “RJ45” port built into every PC sold today.

In datacenters with specialized server hardware, there may be specialized network adapters that communicate directly with many virtual machines. In this case, the VM networks is provided by specialized hardware. However, when you run VMs on your own home or office computer, Windows has to somehow connect both the applications running on the native Windows system and the VMs running on Hyper-V to every type of network adapter that you could choose to plug into your desktop or laptop computer. This includes the LAN adapter on the motherboard, the WiFi card, adapter cards plugged into a PCIe slot, or external adapters connected by USB or Thunderbolt.

In the Kernel, communication from programs to every network adapter goes though device driver support providing the TCP layer process, then the IP layer processing, then the Ethernet layer processing. Once the Ethernet packet is formed, the next step can involve sending the data to a chip on the motherboard, an adapter card, or out the USB connector to hardware that connects to anything.

So, Hyper-V stops at the point where the Ethernet packet has been formed before things get complicated. The Ethernet packet is universal. In the simple case where a VM is talking to a program on the host Windows system, no hardware has to be involved. The Ethernet packet built by a Linux VM can be simply moved in memory to the Windows Kernel, and Ethernet packets built by Windows can be moved in memory to the Linux VM kernel.

Windows has code that turns the host Windows system in to a gateway device for the VMs. Hyper-V always creates a “Default” network to which VMs can be connected, and if that is the only network you define then the VMs can talk to the host computer or the Internet through the Windows host system without any further configuration. However, the Default network does not allow other computers to talk to the VMs.

VMs can be connected to a real LAN adapter so that they appear as real computers on the real network and can communicate with other devices on the network. To do this, an administrator on the Windows host has to select one or more LAN adapters that will either be shared between Windows and the VMs or will be dedicated to the VMs.

If a network adapter is dedicated to one or more VMs, then it is removed from the list of adapters that the Windows applications can see (although the administrator still sees it in the list of devices). Essentially, the Windows Kernel cuts off all of the layers above the Ethernet packet processing for that device. Windows does not provide the socket, TCP, or IP processing.

Meanwhile, in the VM most modern operating systems have a special network device driver that the OS uses when it discovers that it is running in a Hyper-V VM. This Hyper-V VM network adapter supports the socket, TCP, and IP layer processing and stops when the VM has created an Ethernet packet that is ready to be sent out.

Hyper-V provides a service (the “V-bus”) that allows the host Windows Kernel to exchange data with the VMs. Through this service, the Ethernet layer in any VM can send an Ethernet packet to the Windows Kernel, where it is pugged into the Ethernet layer of the real network adapter that was configured to support VM network access. Similarly, Ethernet packets received by the physical network adapter can be sent back to the Ethernet layer of the VM where they move up through the IP, then TCP, then socket layers and are received by the application program running on the VM.

If a physical network adapter on the host Windows system is to be shared between regular Windows applications and also VMs, then when that adapter is prepared by Hyper-V for use by the VMs it is split into two separate “devices”. As in the previous example, on “device” consists of the real adapter starting at the Ethernet packet layer and then proceeding down through the various hardware layers. A separate network adapter is created for use by the Windows applications. It provides the socket, TCP, and IP processing and stops at the Ethernet packet layer. Windows programs can send data through this device, but when the data reaches the Ethernet layer then the packets are transferred inside the Kernel from the “host Windows system network adapter with the top half of the network stack down to and stopping at the Ethernet layer” dummy network adapter to the “host Windows Kernel network adapter bottom half of the network stack starting with Ethernet and going down to the specific real hardware shared between the host system and the VMs” device.

Each VM supervisor (Hyper-V, VMWare, VirtualBox, …) does the same thing, but each has its own way of presenting the three connection options (the Default network where the VMs are isolated inside the host system, a dedicated LAN adapter connected to VMs but not to the host system, or a LAN adapter shared between host applications and VMs).

Hyper-V chooses to present these options through the metaphore of a Virtual Switch. When reading the Hyper-V documentation, it is important to know that Hyper-V doesn’t even try to duplicate the behavior of a real network switch, so you should not assume that this virtual switch behaves in any way like a real switch. It is just an attempt by Microsoft to present the available network configuration options for Virtual Machines while avoiding the real description of Layers of network processing that you have just read.

Hyper-V Virtual Switches

Two physical PCs can be connected to each other by running a simple Ethernet cable between the RJ45 LAN adapter jacks exposed by both machines. This “network” consists of just the two machine cannot be used to access the Internet or anything else.

To connect three or more devices, you need to connect them to a “network switch” device. You can buy them from Amazon or Newegg for (at time or writing) as little as $14. A switch allows every device connected to it to communicate with each other, and if the switch is connected directly or indirectly to a gateway device, they can access the Internet through it.

When you configure a VM in Hyper-V, you can assign it one or more virtual network adapters. Modern operating systems recognize the Hyper-V virtual network adapter as a specific supported device and they have drivers for it.

Hyper-V automatically creates the Default virtual switch. A VM Hyper-V virtual network adapter can be “connected” to the Default switch. Then any network traffic from the VM goes through gateway code in the Windows host system and can access the Internet. However, this gateway logic only supports client programs in the VM and makes them appear to be applications running on the host Windows system. The VMs are hidden from other computers. This is frequently exactly what you want.

Every Hyper-V virtual switch can be connected to any virtual network adapter on any VM. If that is all you do, then the virtual switch is something like buying a $15 physical switch from Amazon and connecting it to unused RJ45 plugs on physical computers you own that presumably get their internet access over WiFi. If the switch is not connected to any gateway, then the computers can use it to exchange data between themselves, but not for anything else.

There are then two things you can do to a Hyper-V virtual switch that make it more interesting. You can connect it to the host Windows application programs and you can connect it to a physical network adapter on the host computer.

This paper has already described both options, but in terms of how they are actually implemented inside the host Windows Kernel by truncating the device driver layers on the physical network device above the Ethernet level and by creating a second dummy network adapter device that has no hardware but supports the socket, TCP, and IP layers above the Ethernet packet layer.

Truncating the upper processing layers and attaching the Ethernet down to the hardware part of a physical Ethernet adapter to a Hyper-V switch changes it to an “External” Hyper-V switch. You can do this when you create the switch or at any time in the future. You can remove an Ethernet adapter from a switch, or you can change which adapter is connected to which switch at any time.

Similarly, at any time you can create a dummy host operating system network adapter that contains only the processing layers down to Ethernet and attach it to any Hyper-V virtual switch.

However

  • You cannot change the Default switch. It is what it is and you leave it alone.

  • You can only have one physical network adapter connected to a switch at any time. You can add an adapter to any switch that doesn’t have one, delete an adapter from any switch that has one, and change the adapter associated with any switch, but there is no provision for two adapters to be connected to the same switch and trying to accomplish this by connecting two switches to a VM with some sort of bridging software will not work. You can connect them to a VM with some router software, but then you are connecting two distinct networks.

  • You can only have one host dummy network adapter connected to a switch at any time.

VLANs

If you don’t know about VLANs or do not use them, ignore this.

Since Hyper-V switches are themselves virtual, you can create as many as you want. The only use for VLANs is when you have a physical network adapter connected to a switch that is connected to a network that not only supports VLANs but where the connection to the adapter is configured as “tagged” (meaning that the adapter can send Ethernet packets with a prefix that selects which VLAN the packet is associated with).

Each VM virtual adapter can be configured with a specific numeric VLAN number, and if the host is sharing use of this physical adapter, then its dummy network adapter connected to the virtual switch can also be assigned a VLAN ID number.