Non standard ssh port

597 views
Skip to first unread message

Tim Haines

unread,
Jul 21, 2011, 2:43:29 PM7/21/11
to Vagrant
Hi there,

I've tried changing the ssh port on my vm to 30002, but after I do
that, I can no longer get vagrant to talk to it.

I've added the port mapping in the Vagrant file, like so:

config.vm.forward_port("ssh", 30002, 2222, :auto => true)

Is there anything else I need to do get vagrant to reload/provision/
ssh successfully after that?

Cheers,

Tim.

Nathan Phelps

unread,
Jul 21, 2011, 2:48:10 PM7/21/11
to vagra...@googlegroups.com
Are you sure iptables is not blocking that port? The default ruleset
will assume the default port.

Nathan

Marco De Bortoli

unread,
Jul 21, 2011, 3:00:25 PM7/21/11
to vagra...@googlegroups.com
Did you configured ssh to run on the port 2222? If not you are then forwarding a port with doesn't have any service listening on.

Marco De Bortoli

unread,
Jul 21, 2011, 3:04:37 PM7/21/11
to vagra...@googlegroups.com
Ops sorry actually the configuration you wrote, is forwarding the guest port 30002 to the host 2222 one which sounds obviously even more strange to me.
By default a ssh forwarding with default ssh service configuration should look like this:

config.vm.forward_port("ssh", 22, 2222, :auto => true)

Where 22 is the default ssh port listening in the guest and 2222 the forwarded port in the host machine.

Does it make sense?

Tim Haines

unread,
Jul 21, 2011, 3:23:25 PM7/21/11
to vagra...@googlegroups.com
Thanks for the responses Nathan and Marco,

I know the default is config.vm.forward_port("ssh", 22, 2222, :auto => true) - I changed the 22 to 30002.

Also, I've checked the iptables are configured for 30002 to be open, and restarted ssh on the vm after I made the port change.

So it sounds like there's not anything obvious that I'm missing?  It appears that vagrant isn't observing the ssh port forwarding rule, but I can't be sure that's what is going on ..


Tim.

Marco De Bortoli

unread,
Jul 21, 2011, 3:36:33 PM7/21/11
to vagra...@googlegroups.com
That's indeed the problem Tim.

It should not like this:

config.vm.forward_port("ssh", 30002, 2222, :auto => true);

but like this

config.vm.forward_port("ssh", 22, 30002, :auto => true);

paremeters in order

config.vm.forward_port([forwarding rule name], [guest port to be forwarded], [host forwarded port], [conflict auto resolve]);

I hope it helps.

Cheers

Tim Haines

unread,
Jul 21, 2011, 4:16:42 PM7/21/11
to vagra...@googlegroups.com
Hi Marco,

Perhaps I didn't explain well.  On the VM itself, I don't want to use port 22 as the ssh port, I have changed it to 30002 on the VM.  So when I set up port forwarding, instead of the host forwarding 2222 to 22 on the vm, I want the host to forward 2222 to 30002.  Does this make sense?

Tim.

Marco De Bortoli

unread,
Jul 21, 2011, 4:52:33 PM7/21/11
to vagra...@googlegroups.com
Oh ok now that make sense I think I misread your first email as well... I have a clean box starting up right now... let me see if I have the same problem. Bear with me.

Marco De Bortoli

unread,
Jul 21, 2011, 5:40:28 PM7/21/11
to vagra...@googlegroups.com
Bad news... it worked like a charme on mine, possibly even better than with the standard forwarding.
The only thing I can think about is that maybe you have another service running on that port.

Did you try to change it to something else?

Tim Haines

unread,
Jul 21, 2011, 5:47:49 PM7/21/11
to vagra...@googlegroups.com
Hi Marco, 

Did you do anything apart from set up the forward_port rule as I did below, and configure it in ssh and iptables in the VM?

Thanks for giving it a shot.

Tim.

Marco De Bortoli

unread,
Jul 21, 2011, 5:53:46 PM7/21/11
to vagra...@googlegroups.com
Actually as per Vagrant's base documentation I disabled both iptables and selinux. I'm currently running a CentOS 5.5 64 bit if it might of any relevance...

What's you host? Win, Mac or Linux? what error message you get if you manually try to do:

ssh vagrant@localhost -p 30002
Reply all
Reply to author
Forward
0 new messages