Build a virtual test lab Part 4: Hyper-V virtual switch

    Introducing virtual switches

    By now we saw how to create a virtual machine and set it’s settings but having a virtual lab does not mean create just one VM and install everything on it. The next part after you create a VM should be to create another one and so on, after all, a single virtual machine could get lonely.

    With the introduction of at least a second machine should come the question: How do I connect them so they can talk to each other? The answer: virtual switches. As you probably know, a switch is a networking device used to connect computers, servers, printers etc. on a Local Area Network. A virtual switch is just the software implementation of how this device acts and lets you connect as many VMs as you have but it also lets you connect virtual machines to the host computer and also to a physical network card (to connect to the internet for example or to communicate with VMs on other hosts). The vswitch can be selected for a VM by going to the network card of that machine and selecting a virtual switch. A VM can have more NICs, each one connected to a different switch if preffered.

    Hyper-V virtual switch types

    Hyper-V lets you create 3 virtual switch types. Each one of them makes it possible to connect the VMs in different ways. Let’s see how they are called and how you can use them:

  • Private virtual switch: A private switch makes it possible to connect together any VM that has it’s NIC set to this switch but no connectivity exists between the virtual machines and the host machine. As you can see from the image below the private switch has 3 VMs connected to it but there is nothing linking this switch with the host machine networking. This is the most common vswitch type you will use in the virtual lab.
private virtual switch

Private virtual switch

  • Internal virtual switch: This one allows you to make a connection between the virtual machines and the host. It is useful if you need to make you physical machine part of the test lab. It does not allow you to exit through any of the physical network cards as can be seen from the picture.
Public virtual switch

Public virtual switch

  • External virtual switch: In this case the switch will be connected to a physical network adapter from the host and the VMs will be able to pass through it. It is possible to include or exclude the host device from being part of this external network if you want to use a specific network card only for virtual machine traffic. This vswitch is useful for connecting the VMs to the internet or if you have 2 or more Hyper-V hosts, to let all VMs communicate with each other no matter where they are hosted.
Public virtual switch

External virtual switch

    In most virtual labs that you will do the only switch needed is the private one. There may be some cases when an internet connection to VMs is necessary; a public switch solves this need without a problem. I haven’t had the use for the internal switch until now but who knows?

    Create a virtual switch

    In this example I want to make a switch for my first test LAN which will have the network address: 192.168.1.0. I want this LAN to be private so no connection to the host is required. Here are the steps to create the switch:

  • Open Hyper-V Manager, right click on your computer name and select Virtual Switch Manager.
Open Virtual Switch Manager

Open Virtual Switch Manager

  • While on the New virtual network switch menu, select Private and click Create Virtual Switch.
Create Private virtual switch

Create Private virtual switch

  • Now select the new adapter and change it’s name to something more suggestive. I like to name my switches like so: <switch type> – <network address>. In this case the name I will use is Priv – 192.168.1.0. Click Apply.
Rename virtual switch

Rename virtual switch

    This is all with creating a private virtual switch. As you can see I have already made a second one for the 192.168.2.0 network which you can do also if you want (you will create it anyway for the next part). There is a third virtual switch named Internet. This one is external and is linked to my Realtek NIC.

    When creating an external vswitch the extra setting to make is selecting which network card to bind to. The Allow management operating system to share this network adapter just means that you are linking you host machine to this switch.

Create External virtual switch

Create External virtual switch

    Notice: Only one virtual switch can be configured to use a specific NIC

    Before ending this part let’s see how to use these switches. I will set the 192.168.1.0 switch on the TEST_VM machine’s network card. Go to Settings and on the Network Adapter tab select the switch and then click Apply.

Set the virtual switch

Set the virtual switch

 

    In the next part we will see how to link 2 or more switches in order to form more complex networks.

 

Leave a Comment

Your email address will not be published. Required fields are marked *