Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Port-forwarding collision when bringing up suspended instances #1740

Closed
markjaquith opened this issue May 15, 2013 · 10 comments
Closed

Port-forwarding collision when bringing up suspended instances #1740

markjaquith opened this issue May 15, 2013 · 10 comments

Comments

@markjaquith
Copy link

I'm still experiencing the #1472 issue when bringing up machines with saved state. The SSH forwarding ports collide and Vagrant bails. vagrant reload (or vagrant halt && vagrant up) gets it to detect and fix the port collision.


Environment:

  • OS X 10.8.3
  • Vagrant 1.2.2
  • VirtualBox 4.2.12 r84980.

Reproduction:

  1. Bring up A.
  2. Suspend A.
  3. Bring up B.
  4. Attempt to bring up A.

Result:

Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 2222 is already in use
on the host machine.


Expected:

Vagrant notices the port collision and switches the port forwarding, allowing vm A to be brought up.

@faceleg
Copy link

faceleg commented Jun 3, 2013

I'm experiencing the same issue

OS X 10.8.3
Vagrant 1.2.2
VirtualBox 4.2.12 r84980

@searls
Copy link

searls commented Jul 3, 2013

👍

Tangent: I even tried setting this up with config.vm.network :forwarded_port, host: 2200, guest: 22 and noticed that vagrant will ignore this directive (well, set it in addition to) the other ssh port.

@mitchellh
Copy link
Contributor

Ah hah. So this is unfortunately working as intended for VirtualBox. VirtualBox doesn't support changing forwarded port mappings when the VM is not powered off. Therefore, you must do a full reload.

If you use the VMware provider, the forwarded ports will auto-correct because it does support changing these while the VM is suspended.

@flomotlik
Copy link

Is there any way to define this when creating the vm? I have two vm's for two different repos that need to be able to run at the same time, but setting the port as @searls tried doesn't work. Any way to change 2222 as the default port

@phunehehe
Copy link
Contributor

I'm on the same boat with @searls and @flomotlik. Is there a way to change the SSH port?

@dmp1ce
Copy link

dmp1ce commented Nov 1, 2013

This configuration worked for me. I was able to start two different VMs from suspend using a different SSH host port.

# Share SSH locally by default
config.vm.network :forwarded_port,
  guest: 22,
  host: 2201,
  id: "ssh",
  auto_correct: true

https://groups.google.com/forum/#!topic/vagrant-up/HwqFegoCXOc

@phunehehe
Copy link
Contributor

That seems to work well. Thanks @dmp1ce!

@rwstauner
Copy link

For the record, I do seem to be able to delete and recreate port-forwards on suspended vm's with VirtualBox 4.3.
I'm not sure if there's more to it than that, but when Vagrant failed to resume I ran the modifyvm commands manually and was then able to resume:

$ VBoxManage modifyvm `cat .vagrant/machines/default/virtualbox/id` --natpf1 delete ssh
$ VBoxManage modifyvm `cat .vagrant/machines/default/virtualbox/id` --natpf1 'ssh,tcp,127.0.0.1,3207,,22'
$ VBoxManage --version
4.3.6r91406

@beporter
Copy link
Contributor

I'm not sure I understand why vagrant can't change the port forwards for a suspended VirtualBox machine if the VBoxManage commands that @rwstauner lists above work. (Contrary to @mitchellh's report on July 23, 2013 before closing this thread, that is.)

@ghost
Copy link

ghost commented Jan 16, 2017

Same issue on OSX. After you set the host port to something else in the Vagrantfile, it seems you need to run vagrant reload for it to take effect. Works for me now.

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants