Search code examples
network-programmingsshvagrantportforwardingvagrantfile

How to know the forwarding port


I have brought a VM using vagrant.In the config vagrant file, I have given

config.vm.network "forwarded_port", guest: 830, host: 8300.

I'm able to ssh in to the VM by

ssh -p 2223 vagrant@localhost

What if i want to spawn multiple VMs of same kind.How to configure the forwarding ports


Solution

  • You can use auto_correct parameter (see https://www.vagrantup.com/docs/networking/forwarded_ports.html); in case of port collision vagrant can assign another port

    config.vm.network "forwarded_port", guest: 830, host: 8300, auto_correct: true
    
    1. you can check vagrant port to displays information about guest port mappings. The command makes a warning about the value

    The forwarded ports for the machine are listed below. Please note that these values may differ from values configured in the Vagrantfile if the provider supports automatic port collision detection and resolution.

    1. just use vagrant ssh to ssh-in into the VM, vagrant will know which port to use.