networking - Vagrant 无法转发此 VM 上的指定端口

标签 networking virtual-machine vagrant

我将 Vagrant 用于一盒配置文件。现在我想将 Vagrant 用于另一个框 (b2),但它说 bioiq 的实例正在消耗转发的端口 2222(它是)。

现在,如果我使用以下配置 b2,Vagrant 仍会尝试使用 2222。

Vagrant.configure("2") do |config|

  config.vm.box = 'precise32'
  config.vm.box_url = 'http://files.vagrantup.com/precise32.box'

  config.vm.network :forwarded_port, guest: 22, host: 2323

  # Neither of these fix my problem 
  # config.vm.network :private_network, type: :dhcp 
  # config.vm.network :private_network, ip: "10.0.0.200"
end

我已经尝试了其他 SO 问题中的各种方法来设置 :forwarded_port (参见 herehere )。我也试过这个 Google Group post ,无济于事。我不断收到这条消息。
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 2222 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: 22, 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.

我不知道为什么 Vagrant 一直无视我的指令。发布的配置不起作用。有没有人克服这个?

最佳答案

在 ssh 端口的情况下,Vagrant 自己解决端口冲突:

==> ubuntu64: Fixed port collision for 22 => 2222. Now on port 2200.

但是,您仍然可以通过以下方式创建不可避免的碰撞:
  • 创建第一个 vagrant env(它将为 ssh 获取端口 2222)
  • 暂停那个 env ( vagrant suspend )
  • 创建第二个 vagrant env(它将再次获得端口 2222,因为它现在未使用)
  • 尝试通过 vagrant up 再次启动第一个环境

  • 您将收到您现在收到的错误消息。

    解决方法是使用vagrant reload , 让 vagrant 丢弃虚拟机状态(这意味着它将以艰难的方式关闭它 - 所以如果你有任何未保存的工作,请小心)并再次启动环境,自行解决任何 ssh 端口冲突。

    关于networking - Vagrant 无法转发此 VM 上的指定端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24127852/

    相关文章:

    c - 数学函数编译器链接错误

    ubuntu - VirtualBox 增加 Ubuntu Linux 的大小 - 未反射(reflect)

    Java UDP多播,判断哪个组发包

    docker - 在 Singularity 中运行 Docker 镜像时绑定(bind)端口

    sockets - 定义 TCP 套接字选项

    ubuntu - Chef 无法运行,因为无法访问 cookbooks 文件夹

    laravel - 将 Laravel 从 vagrant 连接到主机 MSSQL express

    networking - 什么是循环冗余检查以及它如何简单地工作(傻瓜式)?

    vagrant - 名称为 'homestead' 的 VirtualBox 计算机已存在

    vagrant - Vagrant 与docker置备