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
Cannot override default ssh port forwarding #3232
Comments
|
i did comment in the other issue.. what works for me on 1.5.x |
|
I followed @kikitux example in mitchellh#1922 and it worked for me too in 1.5.1 (with OS X version 10.9.2). The difference to the above configuration is that the port forwarding with the ID ssh gets disabled. This syntax feels kind of ill but at least it works. this is not working for me in 1.5.1, but it did in 1.4.3 |
|
I confirm, it works with By the way I think this should be placed somewhere in the docs... it's not so straightforward. |
|
Thanks for the help here @kikitux and @mstoltenburg. I was bitten by this as well in the upgrade to 1.5+, and the workaround of disabling ssh and then mapping it manually does work. It would have been a bit easier to detect if my previous method gave an error or warning of some sort. |
|
I'm having trouble changing the ssh port on the guest machine. I tried the suggestions above config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true
config.vm.network :forwarded_port, guest: 2716, host: 2222, auto_correct: truebut I still get the error message (multiple declarations) on vagrant v1.5.1, ubuntu 12.04 It works if I use another host port (say 2223), e.g.: config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true
config.vm.network :forwarded_port, guest: 2716, host: 2223, auto_correct: true
config.ssh.port = 2223 |
|
you actually have the guest ssh port on 2716 ? On Fri, Mar 21, 2014 at 12:41 AM, xaniasd notifications@github.com wrote:
|
|
in this case yes, sshd is listening to port 2716. Is it a bad idea? |
|
in the sshd add an extra line, from what I know, vagrant WILL ssh into the first interface 22 hardcoded Full Vagrantfile that you can use, is here: https://groups.google.com/d/msg/vagrant-up/mkHSTiKnBpM/Gl9pl_g6JYsJ any question, please send an email to the mailing list Alvaro. On Sun, Mar 23, 2014 at 9:14 PM, xaniasd notifications@github.com wrote:
|
|
Hey Alvaro, thanks for the help. Using another host port (2223 instead of 2222) works without problems with a custom guest port, meaning that vagrant uses port 2716 to log into the first interface. I don't need to enable Port 22 any longer. cheers |
|
This is likely a docs issue. You must specify the ID when overriding. I'll make note of this. |
|
@mitchellh, when you say it's a docs issue, I want to make sure I understand: #Does not work:
config.vm.network :forwarded_port, guest: 22, host: 2230, id: "ssh"#You have to disable the default port first instead:
config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true
config.vm.network :forwarded_port, guest: 22, host: 2230, auto_correct: trueIs that what you intend to clarify in the docs? it's cool if that's what the intention is. I was just surprised at the change in behavior, as well as needing two lines in order to do this now. |
|
I'm seeing this issue too, even when specifying the id, on version 1.5.1 (posting because I can't see this defect linked in the changelogs of 1.5.2 or 1.5.3). |
|
I can report that this does indeed seem to work now, at least as of Vagrant 1.6+ (It might have worked before too - I just hadn't tested past 1.5.1) config.vm.network :forwarded_port, guest: 22, host: 2522, auto_correct: false, id: "ssh" Thanks @mitchellh! |
|
What worked for me was the following as per @xaniasd 's comment config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true ssh in my vagrant box is listening in 22022 |
|
+1 |
|
@mitchellh is right, it's a docs issue. Just do this and it will use 9980 instead of default 2222: |
|
@lsaffie, in your configuration you are permitting Does Vagrant function by defaulting the SSH port to the one specified with |
|
@rvangundy, this configuration worked for me. In fact, I use it on a daily basis. |
|
@lsaffie, it works even if the port is auto-corrected? Would it work if the port was corrected to something other than 22022? |
|
@rvangundy 'vagrant ssh' should work because the vagrant up should have recorded the running config for the vm. If you have multiple vms in the same file you can 'vagrant ssh $NAME' and even if they were all initially configured for port 2222, each successive machine if the auto_correct=true should have its own port, and vagrant keeps track of them. If this isn't the case, there is definitely a hole in the testing cases. In the case of multiple vms in different directories, the same logic should apply. You can run a vagrant global-status to see all the running VMs, which means it keeps track of their states and probably ports somewhere. |
|
By the way, this is probably obvious, but it stumped me for awhile: if it is an existing machine, you have to do |
|
Just doing this worked for me, thank you! config.vm.network :forwarded_port, guest: 22, host: 12345, id: 'ssh' |
|
@Hackeron it also worked for me. Vagrant version is '1.7.2'. |
|
hackeron's comment worked for me as well. Vagrant version is |
|
@Hackeron it also worked for me too!! Vagrant version is '1.7.4'. |
|
@dragon788 I think that @rvangundy is correct. When you deconflict a port using auto_correct and then set the port in config.ssh.host, this will break if the port is actually changed. In my case I have 2 Vagrantfiles that need to do this and when you launch both vagrant's, one of the two will become deconflicted, but when you run ssh, both terminals will ssh into the same box. If you run with VAGRANT_LOG=INFO you'll see that the 'undeconflicted' port is being used via vagrant ssh in both Vagrantfiles. I'm not sure how to get around this. It looks like the problem is that the 'deconfliction' algorithm is a runtime-only feature. When you run 'vagrant ssh' it re-evaluates the Vagrantfile and pulls the 'undeconflicted' port out of the config. (makes sense because there is no way to determine the port collision mapping after the fact...) I added this: I'm going to say that this is a different issue than 'Cannot override default ssh port forwarding'. This has to do with the fact that config.ssh.port should pickup on the deconflicted port change when you have overridden the ssh port. The workaround for this currently is simply to hardcode the host port and not use auto_correct when you are overriding the ssh port. Every thing that needs ssh port forwarding you must simply manually ensure they don't conflict. |
|
Interesting, this could definitely be a bug. You can also run Can you try this and paste back the results to see if it is indeed showing On Mon, Sep 26, 2016 at 4:40 PM, Joseph Gilbert notifications@github.com
|
|
I can't do a 'vagrant port' because I'm using the docker provider and it apparently doesn't support that. However: .... ........ ........ ........ |
|
Both Vagrantfiles have the following:
|
|
Since you've already given it a tagged name of SSH which should set a flag On Sep 26, 2016 5:01 PM, "Joseph Gilbert" notifications@github.com wrote:
|
|
So looking at the documentation the official way to pull this off is not to config.ssh.guest_port - The port on the guest that SSH is running on. This That way it doesn't matter which port it ends up on outside the VM, it will On Sep 26, 2016 6:01 PM, "dragon788" wrote:
|
|
Sadly this does not appear to solve the problem. I wish it did. I've tried various permutations of guest_port/port and no go. If a port re-mapping occurs during the creation of the forwarded port, config.ssh appears to not be aware of the change and ssh connections fail. This only occurs when another Vagrantfile launches something with the exact same port forwards for ssh. For now I'm using something like: |
|
@dragon788 Yea in answer to your question. The reason I was doing it this way is that I'm running docker for mac and they currently have a terrible limitation that there is no docker0 network native on the system. Because of that, 172.17.x.x address are not resolvable. Therefore, if I leave off the config.ssh.xxx stuff, vagrant attempts to ssh into the actual IPV4 address of the container (which is unreachable). Therefore, if you use the docker provider for vagrant (as opposed to docker compose...) and you want to use native docker, you end up here - overriding the ssh port on the container - and discovering that the host ports must be set manually for every container you launch :( |
|
Yeah, it would be great at least to keep config.ssh forwarding to IP 127.0.0.1, at least. This construction is prohibited: Result after It'd be great to have it. I don't know, maybe SSH service can listen globally only. |
|
I'm going to lock this issue because it has been closed for 30 days 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. |
The following configuration does not work anymore on Vagrant 1.5.1.
(Tested 1.5.1 and 1.5.0)
Also tried using the last line alone:
results in Vagrant using the default port 2222 and ignoring the defined 2230.
The
disabled: truesetting is working as expected on vagrant 1.4.3.The text was updated successfully, but these errors were encountered: