Saturday, 10 October 2020

How to forward multiple ports from Vagrant VM to host machine


 You can forward as many ports as you want from Vagrant Virtual machine to your host machine (if those ports are not used by the host), by configure them in VagrantFile as following:

# for Redis
config.vm.network "forwarded_port", guest: 6379, host: 6379
# for HTTP
config.vm.network "forwarded_port", guest: 80, host: 80
# for MySQL
config.vm.network "forwarded_port", guest: 3306, host: 3306

If you want to forward a range of ports, for loop also can be used like this:

for i in 81..89
config.vm.network :forwarded_port, guest: i, host: i
end

for i in 8080..8089
config.vm.network :forwarded_port, guest: i, host: i
end

No comments:

Post a Comment