Vagrant: Port forwarding not working using Win10, Vagrant, Hyper-V, Ubuntu 16.04

Created on 30 Apr 2018  ·  9Comments  ·  Source: hashicorp/vagrant

Vagrant version

2.0.4

Host operating system

Windows 10 with Hyper-V and external network virtual switch

Guest operating system

Ubuntu 16.04

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "kmm/ubuntu-xenial64"
  config.vm.network "forwarded_port", guest: 8011, host: 8080, auto_correct: true
  #config.vm.network "forwarded_port", guest: 8011, host: 8011
  #config.vm.network "forwarded_port", guest: 8012, host: 8012

    if Vagrant.has_plugin?("vagrant-proxyconf")
        config.proxy.http     = "http://proxyseso.YYY.com:8080"
        config.proxy.https    = "http://proxyseso.YYY.com:8080"
        config.proxy.no_proxy = "localhost,127.0.0.1"
    end

config.vm.provider "hyperv"
config.vm.network "public_network"
config.vm.synced_folder ".", "/vagrant", type: "smb",
    smb_password: "XXXX", smb_username: "ZZZ",
    mount_options: ["username=abc","password=XYZ"]
  config.vm.provider "hyperv" do |h|
    h.enable_virtualization_extensions = true
    h.differencing_disk = true
    h.vm_integration_services = {
      guest_service_interface: true  #<---------- this line enables Copy-VMFile
  }
end


  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

Please note, if you are using Homestead or a different Vagrantfile format, we
may be unable to assist with your issue. Try to reproduce the issue using a
vanilla Vagrantfile first.

Debug output

https://gist.github.com/montao/8d4ccd0ac13650ffb42ea15e80a12904

Expected behavior

Port forwarding

Actual behavior

Port forwarding not working

Steps to reproduce

  1. Win10 + Vagrant + Hyper-V + Ubuntu 16.04 + port forwarding
  2. It doesn´t work
  3. Using the IP number instead of localhost/127.0.0.1 works
providehyperv question

Most helpful comment

Hello, Has there been any progress on this? Or a workaround? It seems that without port forwarding vagrant becomes completely useless with HyperV.

Thanks!

All 9 comments

I have similar issue with Win10 (host) + Vagrant + Hyper-V + Windows2016 (guest)

Hi there,

This is currently a limitation of the Hyper-V provider: https://www.vagrantup.com/docs/hyperv/limitations.html#limited-networking

Cheers!

@chrisroberts @sujangrg Thanks for confirming the limitation. It works using the assigned ip number instead of port forwarding. iiuc port forwarding cannot be done with Hyper-V but in my case it works with the ip number instead.

@montao That is correct, currently port forwarding is not available on Hyper-V but is being actively worked on for a future release.

Hello, Has there been any progress on this? Or a workaround? It seems that without port forwarding vagrant becomes completely useless with HyperV.

Thanks!

I have same issue on Windows 10 Pro + Vagrant + VMware. As suggested in previous posts @montao using the IP address instead of localhost does work.

I might be able to offer a workaround:

netsh interface portproxy add v4tov4 listenport=443 listenaddress=* connectport=4443 connectaddress=10.0.2.15

In this example I'm forwarding port 443 on the host to port 4443 on the VM. This relies on the VM consistently having IP address 10.0.2.15, in my case.

Potentially also relevant:
https://www.petri.com/configuring-vm-networking-hyper-v-nat-switch
The valuable part of that code is the function at https://gist.github.com/foglcz/28a2a3fc00edffdb9cb3 which enables you to apply an IP address to a Hyper-V guest from the host. It worked for me with an Ubuntu 16.04 guest on Hyper-V on 10.0.17763 (update 1809).

Not useful for me, but YMMV:
https://4sysops.com/archives/where-did-the-native-nat-switch-go-in-windows-10-1607/
https://4sysops.com/archives/native-nat-in-windows-10-hyper-v-using-a-nat-virtual-switch/

@troyscott I have a similar setup.

Windows 10 Pro + Vagrant (ubuntu 18.04) + Virtualbox and using the IP 10.0.2.15 (taken from ifconfig) instead of localhost also fails for me.

@fsackur also tried your solution but that did not enable localhost.

Terrible workaround for me was to install lxde desktop environment on top of ubuntu server and flip on vb.gui = true and give up port forwarding. Other workaround is for me to dual boot the laptop but neither of which are good workarounds 🙄 😄

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

barkingfoodog picture barkingfoodog  ·  3Comments

jazzfog picture jazzfog  ·  3Comments

Cbeck527 picture Cbeck527  ·  3Comments

RobertSwirsky picture RobertSwirsky  ·  3Comments

DreadPirateShawn picture DreadPirateShawn  ·  3Comments