- Working with Vagrant and Hyper-V
- Vagrant Hyper-V Provider
- Creating an external virtual switch in hyper-v
- What to do if Hyper-V Manager is not found
DockerNAT
prevents other internal interfaces from working
These notes will help to:
- configure an internal virtual network interface (
vEthernet
) in Hyper-V - set it up so it can access the internet from your laptop's WiFi connection
- use it in Vagrant so that your Vagrant box will be provisioned successfully with
hyperv
provider.
- Open Hyper-V Manager. Look at the References section if you cannot find Hyper-V Manager.
- Click your machine name on left panel. On the right-most panel you will find the option
Virtual Switch Manager
. Click that. - Create an Internal interface. Name it "InternalSwitch".
- Now you need to configure your WiFi's network adapter.
- In the
Run
Dialog, typecontrol netconnections
. This opens the Network Adapter window. - Right-click your WiFi network adapter, open
Properties
>Sharing
tab. - Configure sharing between WiFi adapter and the
InternalSwitch
virtual interface created above.
❗ *If your VM is running while you configure network, please restart the VM (vagrant reload
) !
Next, configure the IPV4 Settings for the InternalSwitch
adapter.
- Open properties for the
InternalSwitch
adapter. - Click "Internet Protocol Version 4" and click "Properties".
And then configure its properties as follows (only the DNS address may be missing usually):
At this point, if you have Docker for Windows running, your virtual interface will show "No Internet Access". See the references section; there is documentation that says only one such internal interface can be used at a time.
Quit Docker.
The network interface will now show an internet connection.
Its assumed you have a Vagrantfile
with a hyperv
box and configuration - example this Vagrantfile
.
Run vagrant up --provider=hyperv
.
❗️ Make sure to from an elevated terminal. ❗️ Vagrant does not allow auto-configuring the interface. It will ask you to choose the interface, select the appropriate number:
devops-host: Please choose a switch to attach to your Hyper-V instance.
devops-host: If none of these are appropriate, please open the Hyper-V manager
devops-host: to create a new virtual switch.
devops-host:
devops-host: 1) DockerNAT
devops-host: 2) Layered_Wi-Fi
devops-host: 3) InternalSwitch
devops-host:
devops-host: What switch would you like to use? 3
==> devops-host: Waiting for the machine to report its IP address...
devops-host: Timeout: 120 seconds
Hyper-V failed to determine your machine's IP address within the
configured timeout. Please verify the machine properly booted and
the network works. To do this, open the Hyper-V manager, find your
virtual machine, and connect to it.
The most common cause for this error is that the running virtual
machine doesn't have the latest Hyper-V integration drivers. Please
research for your operating system how to install these in order
for the VM to properly communicate its IP address to Hyper-V.
The root cause is that it runs a script C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.9.7\plugins\providers\hyperv\scripts\get_network_config.ps1
which ultimately calls Get-VMNetworkAdapter
.
And this cmdlet returns empty IP addresses, which trips up vagrant.
Get-VMNetworkAdapter -VMName devops-host
Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses
---- -------------- ------ ---------- ---------- ------ -----------
Network Adapter False devops-host InternalSwitch 00155D570114 {Degraded, ProtocolVersion} {}
Cause #1: the Vagrant Box itself
There is very little documentation on this online. Some references:
- hashicorp/vagrant#3247
- technet forum post that says this could be related to the way the Linux VM is created.
I tried switching different Vagrant hyperv
boxes:
generic/ubuntu1604
: 👎kmm/ubuntu-xenial64
: 👍 This worked and went past the timeout!
Cause #2: IPV6
On one occasion, I had to make sure that IPV6 was disabled on the network properties for the InternalSwitch
virtual interface.
Cause #3: hv_kvp_daemon
service on Ubuntu
On another occasion, I had to install a set of packages inside my Ubuntu Hyper-V VM to ensure it connects properly.
The package was called linux-cloud-tools
or something ( link )