Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 14 Next »

Hyper-V Virtual Switches

Virtual Machines communicate over one or more simulated wired Ethernet networks. It is too hard to simulate a WiFi network. Real wired networks are built by connecting an Ethernet cable from the port in a computer to a device called a “switch”. When a switch fills up, you can connect a wire from that switch to a second switch and so on. All the computer ports connected to this set of connected switches forms a network of computers.

Other Virtual Machine systems simply configure network names and connect a VM to the network by name. Hyper-V decided to create a named “virtual switch” for what other systems simply call a “virtual network”. This metaphor may not be helpful because a Hyper-V “virtual switch” does not really behave in exactly the same way that a physical network switch operates. In particular, you cannot connect or bridge one Hyper-V virtual switch to another virtual switch.

The Hyper-V virtual Ethernet adapter in any VM does not simulate any physical adapter you can buy for a real machine. Microsoft provides Windows and Linux drivers for their virtual adapter, and a few other operating systems, particularly freeBSD, have modified the Linux driver so it works in their system.

Standard operating system services convert application data to TCP packets which are then enclosed in IP packets which are then enclosed in Ethernet frames. All that work is the same no matter what Ethernet adapter is being used. The Ethernet frame is then turned over to the hardware vendor driver which sends the frame out through the adapter. The Hyper-V driver sends the frame over the virtual bus that connects the VMs to the Kernel of the host Windows system.

Hyper-V can create a network that is entirely virtual. VMs can use it to talk to each other, but there is no direct connection to any physical external network. One VM or the host Windows system can act as a “gateway” to the Internet by receiving data from the virtual network, rewrite it (NAT) so it looks like it was sent by an application on the gateway computer, and then forwarding the data out to the Internet. If there is network level malware scanning installed on the gateway system, it may provide protection for the downstream hosts.

Alternately, Hyper-V can create an “External” network that is associated with a single physical Ethernet device on the Host system. Ethernet packets sent by one Hyper-V virtual Ethernet adapter that are not addressed to another Hyper-V virtual Ethernet adapter on the same network virtual switch are sent out through the physical adapter attached to that virtual switch. The packets then go to whatever network the physical Ethernet adapter is connected to. Each virtual Ethernet adapter on each VM has its own Ethernet 6-byte ID value, so each VM appears to the external network as a real computer connected to the real network.

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.

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.

Creating a physical LAN port in the real world for something that is otherwise virtual may be a useful trick for specialized types of network connections. More generally, VLAN capability allows a single network adapter to behave as multiple LAN adapters connected to different devices or networks, which can save money and PCIe slots in more complicated networking situations.

  • No labels