In this article I will explain how to setup the network and Hyper-V to give internet access to a lan of virtual machines my way.
Why am I doing this? On my daily developpeur laptop I have Hyper-V installed with at least two virtual machines running in the same subnet:
Why am I doing this? On my daily developpeur laptop I have Hyper-V installed with at least two virtual machines running in the same subnet:
- DEV-DC : Active Directory, DNS, Certificate Authority + other domain related...
- DEV-SP2013 : My SharePoint developer environnement with Visual Studio
My goal is to give them internet access using my host as a gateway and still have the subnet working even if I'm offline.
Both machines are in the "*.dev.lab" domain. To simulate something close to an enterprise network DEV-SP2013 uses domaine accounts and the DNS service from DEV-DC.
So in order to logon to DEV-SP2013 the AD must be on the same network. In Hyper-V you have multiple options to achieve this:
External network : Will require a physical adapter effectively connected to a network (wifi or ethernet), else VMs won't see each other. Plus both VMs virtual adapters will have to be set to DHCP to get an IP on the physical adapter's network, this means troubles to use DEV-DC's DNS.
Private network : VMs will see each other but no internet access possible through the host.
Internal network : This will create a vLan network between VM's and the host machine. The host machine will have a virtual adapter on the vLan that will appear like a physical adapter in Windows.
Yes, "Internal Network" is the way to go, you get a vLan between machines and you get to control connexion with external networks by routing through the host machine.
For this I use "Internet Sharing" and set the vLan to use the default network IP range assign automatically when you enable sharing (192.168.137.0/24).
To enable internet Sharing from the host Windows:
Go to network adapters and right clic the adapter that has access to Internet and select properties (I my case I will use my wifi card).
Next you need to configure VMs adapters with fixed IPs to go through the adapter:
IP:192.168.137.XXX (the fixed ip)
Mask: 255.255.255.0
Gateway: 192.168.137.1
In order to use the DNS service on DEV-DC my setup goes like this:
DEV-DC
IP:192.168.137.2
Mask: 255.255.255.0
Gateway: 192.168.137.1
DEV-SP2013
IP:192.168.137.100
Mask: 255.255.255.0
Gateway: 192.168.137.1
Primary DNS: 192.168.137.2
Final step, setup the DNS service of DEV-DC to forward unknown DNS queries (for internet).
Open the "DNS Manager" and right clic the domain node and clic properties:
External network : Will require a physical adapter effectively connected to a network (wifi or ethernet), else VMs won't see each other. Plus both VMs virtual adapters will have to be set to DHCP to get an IP on the physical adapter's network, this means troubles to use DEV-DC's DNS.
Private network : VMs will see each other but no internet access possible through the host.
Internal network : This will create a vLan network between VM's and the host machine. The host machine will have a virtual adapter on the vLan that will appear like a physical adapter in Windows.
Yes, "Internal Network" is the way to go, you get a vLan between machines and you get to control connexion with external networks by routing through the host machine.
For this I use "Internet Sharing" and set the vLan to use the default network IP range assign automatically when you enable sharing (192.168.137.0/24).
To enable internet Sharing from the host Windows:
Go to network adapters and right clic the adapter that has access to Internet and select properties (I my case I will use my wifi card).
Select the "Share" tab and check allow sharing. If you have multiple adapters select the target you want to share to (the hyperv vLan), the target will automatically have it's IP assigner to 192.168.137.1
Next you need to configure VMs adapters with fixed IPs to go through the adapter:
IP:192.168.137.XXX (the fixed ip)
Mask: 255.255.255.0
Gateway: 192.168.137.1
In order to use the DNS service on DEV-DC my setup goes like this:
DEV-DC
IP:192.168.137.2
Mask: 255.255.255.0
Gateway: 192.168.137.1
DEV-SP2013
IP:192.168.137.100
Mask: 255.255.255.0
Gateway: 192.168.137.1
Primary DNS: 192.168.137.2
Final step, setup the DNS service of DEV-DC to forward unknown DNS queries (for internet).
Open the "DNS Manager" and right clic the domain node and clic properties:
Go to the "Forwarders" tab and add "8.8.8.8" (Google's public DNS):
Then restart the DNS service:
Conclusion, from you have a functional vLan that will work no matter if you are on a physical network or not. Plus as soon as the physical network gives you access to internet the vLan will also have access.
Comments