Anyway to control the host port from Vagrantfile?

22 views
Skip to first unread message

Joaquin Menchaca

unread,
Aug 5, 2015, 9:32:00 PM8/5/15
to Vagrant
Is there anyway to configure the host port instead of having this automatically decided?

==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)


I would like to set the port to something of my own design, not have it auto assigned 2222.

Alvaro Miranda Aguilera

unread,
Aug 5, 2015, 9:42:04 PM8/5/15
to vagra...@googlegroups.com
yes you can:

try this:

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

config.vm.network :forwarded_port, guest: 22, host: 2230
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/mitchellh/vagrant/issues
> IRC: #vagrant on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vagrant-up+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vagrant-up/40f38501-ab20-400e-86b1-9460535ca0ee%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Joaquin Menchaca

unread,
Aug 5, 2015, 9:54:20 PM8/5/15
to Vagrant
Thanks.  Perfect.

I found by luck a ticket on when this didn't work... https://github.com/mitchellh/vagrant/issues/3232

I am uses a file to coordinate the ports so that I can remote into them with vagrant and do hostname configuration.

  ssh_port = open('../../provisioning/vagrant.ini').grep(/#{config.vm.hostname}/)[0].split(/[=\s]/)[4]
  config.vm.network :forwarded_port, guest: 22, host: ssh_port, id: "ssh"

Reply all
Reply to author
Forward
0 new messages