frapposelli / vagrant-vcenter

A Vagrant provider for VMware vCenter®
MIT License
107 stars 36 forks source link

Vagrant forwarded_ports don't seem to work #22

Open hsmanninen opened 9 years ago

hsmanninen commented 9 years ago

Hello,

when trying to set up a Vagrant VM with custom forwarded ports like this: config.vm.network :forwarded_port, guest: 1234, host: 1234 (https://docs.vagrantup.com/v2/networking/forwarded_ports.html) it seems to be doing nothing.

Is this a known feature limitation or...?

Heikki M

frapposelli commented 9 years ago

There is no forwarded ports functionality in vagrant-vcenter as there is really nothing to forward ports to, VMs created are connected directly to the network specified unfiltered, what are you trying to accomplish with that?

hsmanninen commented 9 years ago

Thanks for the answer. I understand that this is the case with vCenter usually. But I would say that forwarding ports is one the most useful things in Vagrant... for example: you can write a single set of unit tests that all can be configured to use e.g. "127.0.0.1:1234" as a backend database address. No matter how many concurrent instances you have running, they will always connect to their own provisioned test backend.

It's all about not having to know/care at all about the actual IP address of the provisioned virtual machine.

The way it works with VirtualBox and Fusion also.

frapposelli commented 9 years ago

I get your point, problem is that VirtualBox and Fusion have a NAT service that fronts VMs and Vagrant controls that NAT service doing port mapping, there is no such thing for ESXi/vCenter (the vCloud and vCloud Air providers actually support the port map feature because it can provision a vShield Edge that does the NAT).

The only way you can accomplish that is by creating the port forward INSIDE the VM you're deploying using iptables, something like this:

iptables -t nat -A OUTPUT -p tcp -d 127.0.0.0/8 --dport 80 -j REDIRECT --to-port 1234

you can put that in an inline shell provider and have 127.0.0.1:80 redirected to 127.0.0.1:1234.

hsmanninen commented 9 years ago

Thanks, sure there are workarounds. I'm currently doing on-the-fly SSH tunnels to overcome this. It's just the beauty of Vagrant handling all that :) Not sure if I understood your suggestion but what I'm after is port forwarding local ports on the Vagrant host to the specified port of the remote guest VM. Not forwarding ports within the guest VM.

Actually I was under the impression that Vagrant did the port forwards using SSH also when using remote virtual machines instead of local like VBox and Fusion.

frapposelli commented 9 years ago

Ok, I get what you want to do now :) I may need to double check in vagrant core if there are builtins to do SSH port forwarding, will keep this open and see what I can do.

thanks for the suggestion!

hsmanninen commented 9 years ago

Thanks! I looked at Vagrant a bit and it could be that this is not implemented using SSH at all... but I see no reason why it couldn't be. Would be really nice to be able to use same networking layouts for multi-machine environments regardless whether you're using local workstation/fusion stuff or remote vcenter/vcloud.