Change Vagrant port forwarding on a running system

19,912

Solution 1

Have you tried using the VirtualBox user interface to add the new port forwarding rule manually? Open VirtualBox and select the running VM, then hit Settings->Network->Port Forwarding and add the new rule to, for example, forward 127.0.0.1:2223 to 10.0.2.15:22. After doing this I was able to connect to my VM on ports 2222 (as per usual) and 2223 (the new rule).

Naturally, you would add this new rule to your Vagrantfile at the same time to ensure that the mapping becomes permanent after the eventual restart.

Also, if your VM provisioning takes so long, have you considered moving some of the chef/puppet steps into the actual base box? For example, perhaps you are installing a bunch of server software that takes a while to install. Repackaging the box with this software already installed could dramatically reduce your Vagrant startup time.

Hope this helps!

Solution 2

you can do

vagrant reload --no-provision

and it should run without chef, puppet, etc.

although it will still reboot the vm- feels like "But if you have an already running system..." is maybe a bit misleading.

Share:
19,912
Roberto Aloi
Author by

Roberto Aloi

Because of my academic career, I’m interested in software engineering, human - computer interaction, user interfaces, graphics, databases, web applications and more. As the final thesis for my Bachelor's degree, I implemented a garbage collector for a Java Virtual Machine (named Juice) targeted to embedded systems with real time requirements. As the final thesis for my Master's degree, I designed an access control mechanism for the Content Management System Joomla (www.joomla.org). It was successfully used for an e-learning solution. I spent my last years discovering the Erlang language and getting addicted to it.

Updated on June 03, 2022

Comments

  • Roberto Aloi
    Roberto Aloi almost 2 years

    I have a Vagrant system up and running and I want to apply a change to it which is as little as changing one of the forwarding rules.

    From this page:

    Forwarded ports are applied during vagrant up like any other configuration. But if you already have a running system, calling vagrant reload will apply them without re-importing and re-building everything.

    Note that forwarding ports requires a virtual machine restart since VirtualBox won’t pick up on the forwarded ports until it is completely restarted.

    Sounds exactly like what I want! But if I try a vagrant reload all of my Chef recipes are reloaded and since the full process takes about half an hour, I have to go to the kitchen and grab the nth cup of coffee.

    Is there any way to apply Vagrantfile changes on a running system without going trough the whole provisioning process? I cannot drink so much coffee.

  • Alexander.Iljushkin
    Alexander.Iljushkin over 9 years
    Thank you bro, extremly simple and fast applied solution
  • TimoSolo
    TimoSolo almost 8 years
    Restarting the VM is the problem though even if a bit faster
  • marios
    marios over 7 years
    For anyone reading, the next answer by awongh might be what you are looking for.
  • Dawngerpony
    Dawngerpony over 7 years
    Yup, although the VM restart may not be what is wanted. (And that command didn't exist in 2011 when I wrote the above answer!)