使用相同端口转发规则的多个 VM 的端口转发 [英] Portforwarding for multiple VMs using same port forwarding rules

查看:64
本文介绍了使用相同端口转发规则的多个 VM 的端口转发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个 vagrant 环境,其中每个 VM 都有一个从主机到来宾的端口转发规则设置.然而,这个转发规则的问题是我不能同时通过 vagrant 运行多个具有类似端口转发规则的虚拟机.

I currently have a vagrant environment where each VM has a port forwarding rule setup from host to guest. However the problem with this forwarding rule is that I cannot have multiple VMs running via vagrant at the same time with similar port forwarding rules.

看来我需要某种端口代理来处理这个问题.是否有一些已经融入 vagrant/virtualbox 的东西可以支持这一点?

It seems like I'll need some sort of a proxy for ports to handle this. Is there something that is already baked into vagrant/virtualbox that could support this?

Traceback from Vagrant when I try running another VM with the same forwarding rules:
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 8000 is already in use
on the host machine.

To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

 config.vm.network :forwarded_port, guest: 8000, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding.

推荐答案

您可以使用 :auto_correct 参数进行端口定义,然后 Vagrant 将寻找另一个(未使用的)端口:

You can use the :auto_correct parameter for the port definition, then Vagrant will look for another (non-used) port:

Vagrant.configure("2") do |config|
  config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
end

有关详细信息,请参阅文档.

See the documentation for more details.

这篇关于使用相同端口转发规则的多个 VM 的端口转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆