Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save doggy8088/8294d0e1029787fb61613a7b5ce49905 to your computer and use it in GitHub Desktop.
Save doggy8088/8294d0e1029787fb61613a7b5ce49905 to your computer and use it in GitHub Desktop.
Notes on Vagrant and Hyper-V

Vagrant and Hyper-V: Working with Virtual Network Interfaces

References

Introduction

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.

1. Create Virtual Network Interface

  1. Open Hyper-V Manager. Look at the References section if you cannot find Hyper-V Manager.
  2. Click your machine name on left panel. On the right-most panel you will find the option Virtual Switch Manager. Click that.
  3. Create an Internal interface. Name it "InternalSwitch".

image

2a. Setup Network Sharing between WiFi and InternalSwitch

  1. Now you need to configure your WiFi's network adapter.
  2. In the Run Dialog, type control netconnections. This opens the Network Adapter window.
  3. Right-click your WiFi network adapter, open Properties > Sharing tab.
  4. Configure sharing between WiFi adapter and the InternalSwitch virtual interface created above.

image

3. Configure IPV4 Settings for InternalSwitch

❗ *If your VM is running while you configure network, please restart the VM (vagrant reload) !

Next, configure the IPV4 Settings for the InternalSwitch adapter.

  1. Open properties for the InternalSwitch adapter.
  2. Click "Internet Protocol Version 4" and click "Properties".

And then configure its properties as follows (only the DNS address may be missing usually):

image

4. Make sure Docker for Windows is turned off

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.

image

Quit Docker.

image

The network interface will now show an internet connection.

image

5. Execute vagrant up

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

Troubleshooting: Error during vagrant up: failed to get IP address

==> 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:

  1. hashicorp/vagrant#3247
  2. 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!

image

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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment