Host port already in use by forwarded_port rule
0 reputation · 05 May 2020, 10:47 UTC
Goal: Define a config.vm.network :forwarded_port mapping in a Vagrantfile that exposes a guest TCP service on a chosen host port without disrupting an existing host listener.
Constraint: Vagrant regenerates host-level NAT forwarding rules on every vagrant up and vagrant reload, and the mapping remains active for the VM lifetime. Host operating systems differ: Linux uses iptables, Windows uses netsh. Vagrant 2.2 and earlier do not support the guest option, while 2.3.x added it to influence rule syntax.
Uncertainty: It is not documented whether Vagrant validates host-port availability before creating the rule, what happens when another process already binds the port, or how to detect the conflict before the VM starts.
- Does Vagrant abort VM startup if the configured host port is already in use?
- Can a Vagrantfile detect an existing host listener and select an alternate host port automatically?
- Does the
guestoption change conflict behavior on Vagrant 2.3.x compared with earlier releases?