Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

give a chance to disable default ssh port forwarding #1922

Closed
pniederlag opened this issue Jul 12, 2013 · 16 comments

Comments

@pniederlag
Copy link

@pniederlag pniederlag commented Jul 12, 2013

from config/default.rb

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

it seems impossible to disable this port_forwarding which in turn really requires the first interface to be a NAT interface.

@apinstein

This comment has been minimized.

Copy link

@apinstein apinstein commented Aug 21, 2013

This is a very serious problem for any of us that use 2 boxes at the same time.

I cannot presently get 2 boxes to boot simultaneously as the 2nd boot complains that port 2222 is already in use and I cannot find any workaround.

Any update on this issue?

@canausa

This comment has been minimized.

Copy link
Contributor

@canausa canausa commented Aug 21, 2013

What version of Vagrant are you using? I seem to have no problems, running
multiple boxes at the same time.

On Wed, Aug 21, 2013 at 10:47 AM, Alan Pinstein notifications@github.comwrote:

This is a very serious problem for any of us that use 2 boxes at the same
time.

I cannot presently get 2 boxes to boot simultaneously as the 2nd boot
complains that port 2222 is already in use and I cannot find any workaround.

Any update on this issue?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1922#issuecomment-23022444
.

@apinstein

This comment has been minimized.

Copy link

@apinstein apinstein commented Aug 21, 2013

1.2.7, just upgraded today to see if it's fixed.

All of my boxes use private networking, that might be the thing that "reveals" this bug.

On Aug 21, 2013, at 11:18 AM, canausa notifications@github.com wrote:

What version of Vagrant are you using? I seem to have no problems, running
multiple boxes at the same time.

On Wed, Aug 21, 2013 at 10:47 AM, Alan Pinstein notifications@github.comwrote:

This is a very serious problem for any of us that use 2 boxes at the same
time.

I cannot presently get 2 boxes to boot simultaneously as the 2nd boot
complains that port 2222 is already in use and I cannot find any workaround.

Any update on this issue?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1922#issuecomment-23022444
.


Reply to this email directly or view it on GitHub.

mitchellh added a commit that referenced this issue Aug 29, 2013
@mitchellh

This comment has been minimized.

Copy link
Member

@mitchellh mitchellh commented Aug 29, 2013

You can now set disabled: true on forwarded ports to disable them. You can override (always have been able to do this) by matching the same host port and protocol.

@mitchellh mitchellh closed this Aug 29, 2013
@apinstein

This comment has been minimized.

Copy link

@apinstein apinstein commented Aug 29, 2013

So, this would be the expected syntax to "disable" the built-in port forwarding?

# once we're on our custom port, disable the built-in host -> guest:22 forwarding so that we can spin up multiple vagrants without incident.
config.vm.network :forwarded_port, guest: 22, disabled: true

Incidentally, I wouldn't have cared about the default 2222->22 forwarding so long as the auto-collision detection worked... but it didn't seem to... is that a known bug or should I file something there, too?

@mitchellh

This comment has been minimized.

Copy link
Member

@mitchellh mitchellh commented Aug 29, 2013

@apinstein It does seem odd the collision detection didn't work actually. Is this Windows or Linux? And its keyed by host port, so set the "host:"

@apinstein

This comment has been minimized.

Copy link

@apinstein apinstein commented Aug 29, 2013

It was on Mac OS Host / Linux guest(s).

On Aug 29, 2013, at 4:24 PM, Mitchell Hashimoto notifications@github.com wrote:

@apinstein It does seem odd the collision detection didn't work actually. Is this Windows or Linux? And its keyed by host port, so set the "host:"


Reply to this email directly or view it on GitHub.

@mitchellh

This comment has been minimized.

Copy link
Member

@mitchellh mitchellh commented Aug 29, 2013

If you can make a minimal reproducible case then yes please do report a bug.

@apinstein

This comment has been minimized.

Copy link

@apinstein apinstein commented Aug 29, 2013

Ok, will do if I get time…

On Aug 29, 2013, at 4:28 PM, Mitchell Hashimoto notifications@github.com wrote:

If you can make a minimal reproducible case then yes please do report a bug.


Reply to this email directly or view it on GitHub.

@bdcribbs

This comment has been minimized.

Copy link

@bdcribbs bdcribbs commented Sep 7, 2013

This doesn't work for me in 1.3.1 on OSX, because the config validation complains:

* Forwarded port '2222' (host port) is declared multiple times
with the protocol 'tcp'.

I believe this is easily fixed by skipping the network validation in plugins/kernel_v2/config/vm.rb when options[:disabled] is set (This is already done for shared folders).

Follow-up
Skipping the validation gets past the error mentioned above, but the port forward is still not disabled.

To reproduce:

  • vagrant init an empty project, and edit the Vagrantfile and ensure the following line is present:
    • config.vm.network :forwarded_port, guest: 80, host: 8080
  • In your ~/.vagrant.d/Vagrantfile, include the line
    • config.vm.network :forwarded_port, guest: 80, host: 8080, disabled: true
  • vagrant up
    • [BUG] Host port 8080 is still forwarded to guest port 80.
@apinstein

This comment has been minimized.

Copy link

@apinstein apinstein commented Sep 12, 2013

I run into the same problem as @bdcribbs ... on 1.3.1, upgraded just to try this feature.

@j0hnsmith

This comment has been minimized.

Copy link

@j0hnsmith j0hnsmith commented Nov 28, 2013

config.vm.network :forwarded_port, guest: 22, host: 2222, disabled: true

Results in * Forwarded port '2222' (host port) is declared multiple times with the protocol 'tcp'.

The only way I was able to change the default forward port was by using

config.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2223

I'm using vagrant 1.3.5 on OSX.

@shawnzhu

This comment has been minimized.

Copy link

@shawnzhu shawnzhu commented Jan 29, 2014

I didn't specify any network configuration in Vagrantfile for ssh forwarded port collision on vagrant 1.3.1 on OSX. command vagrant reload does work to resolve ssh port collision automatically:

$ vagrant reload
[default] Attempting graceful shutdown of VM...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 22 => 2222. Now on port 2200.
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2200 (adapter 1)
[default] Booting VM...
@apinstein

This comment has been minimized.

Copy link

@apinstein apinstein commented Jan 29, 2014

I do believe it works fine when no networking is provided, however if you use private networking for your guests you cannot have 2+ up a the same time due to port collisions.

On Jan 29, 2014, at 11:53 AM, shawnzhu notifications@github.com wrote:

I didn't specify any network configuration in Vagrantfile for ssh forwarded port collision on vagrant 1.3.1 on OSX. command vagrant reload does work to resolve ssh port collision automatically:

$ vagrant reload
[default] Attempting graceful shutdown of VM...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 22 => 2222. Now on port 2200.
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2200 (adapter 1)
[default] Booting VM...

Reply to this email directly or view it on GitHub.

@abarani

This comment has been minimized.

Copy link

@abarani abarani commented Mar 15, 2014

opened new issue: #3232

@kikitux

This comment has been minimized.

Copy link
Contributor

@kikitux kikitux commented Mar 17, 2014

This works for me:

config.vm.network :forwarded_port, guest: 22, host: 2200, id: "ssh",
disabled: "true"
config.vm.network :forwarded_port, guest: 22, host: 2230

==> default: Forwarding ports...
default: 80 => 9082 (adapter 1)
default: 22 => 2230 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2230
default: SSH username: vagrant
default: SSH auth method: private key

On Sun, Mar 16, 2014 at 6:34 AM, Andrea Barani notifications@github.comwrote:

opened new issue: #3232 #3232

Reply to this email directly or view it on GitHubhttps://github.com//issues/1922#issuecomment-37732220
.

@qasimzee

This comment has been minimized.

Copy link

@qasimzee qasimzee commented Apr 8, 2015

Also getting the same issue as 8080 port setting was available in packaged vagrant file of the box. Following line helped me.

config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct: true

glinton added a commit to nanobox-io/nanobox that referenced this issue Nov 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants
You can’t perform that action at this time.