无法连接到使用nat和hostonly vagrant和virtualbox设置的来宾节点

时间:2015-05-12 11:25:40

标签: vagrant virtualbox

我一直在尝试用vagrant替换手动的vitualbox设置。我通常创建一个带有2个网络适配器的访客节点,一个NAT用于访客(ubuntu),使用主机互联网进行所有apt-get操作,以及一个hostonly用于我的主机连接到访客。我工作得很好。

以下是我的流浪文件

Vagrant.configure("1") do |config|
  config.vm.boot_mode = :gui
end

Vagrant.configure("2") do |config|
  config.vm.define "web" do |web|
    web.vm.box = "ubuntu/trusty64"
      web.vm.network "forwarded_port", guest:22, host:2222, id:"ssh", disabled:true 
      web.vm.network "private_network", ip:"192.168.56.103", :adapter =>2
    end

end 

以下是输出:

Bringing machine 'web' up with 'virtualbox' provider...
==> web: Importing base box 'ubuntu/trusty64'...
==> web: Matching MAC address for NAT networking...
==> web: Checking if box 'ubuntu/trusty64' is up to date...
==> web: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> web: have version '14.04'. The latest is version '20150430.0.0'. Run
==> web: `vagrant box update` to update.
==> web: Setting the name of the VM: ansible_web_1431424632866_64634
==> web: Clearing any previously set forwarded ports...
==> web: Clearing any previously set network interfaces...
==> web: Preparing network interfaces based on configuration...
    web: Adapter 1: nat
    web: Adapter 2: hostonly
==> web: Forwarding ports...
==> web: Booting VM...
==> web: Waiting for machine to boot. This may take a few minutes...
    web: SSH address: 127.0.0.1:22
    web: SSH username: vagrant
    web: SSH auth method: private key
    web: Warning: Authentication failure. Retrying...
    web: Warning: Authentication failure. Retrying...
    web: Warning: Authentication failure. Retrying...

现在对流浪者来说,它几乎可以工作,我无法弄清楚几件事情:
问题1 流浪者是否需要端口转发才能连接到访客? 问题2 当流浪汉说:==> web: Preparing network interfaces based on configuration... web: Adapter 1: nat web: Adapter 2: hostonly我认为eth1应该是up,但事实并非如此。 ifconfig -a显示没有任何IP的接口eth1 sudo ifup eth1显示Ignoring unknown interface eth1=eth1。这里发生了什么,我该如何解决这个问题?

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

没关系,我修好了。这在很大程度上依赖于使用的流浪者版本。这适用于支持转发端口自动更正功能的任何版本。

删除该行后:

web.vm.network "forwarded_port", guest:22, host:2222, id:"ssh", disabled:true 

它开始像魅力一样工作,我可以添加其他节点。请在下面看看为了共享而工作的配置

Vagrant.configure("1") do |config|
  config.vm.boot_mode = :gui
end

Vagrant.configure("2") do |config|
  auto_config= false

    config.vm.define "web" do |web|
       web.vm.box = "ubuntu/trusty64"
       web.vm.network "private_network", ip:"192.168.56.103", :adapter =>2
    end

   (1..3).each do |i|
      config.vm.define "mongo-#{i}" do |mongo|
         mongo.vm.box = "ubuntu/trusty64"
         mongo.vm.network "private_network" , ip:"192.168.56.11#{i}", :adapter =>2
     end
   end 

  (1..2).each do |i|
    config.vm.define "tomcat-#{i}" do |tomcat|
      tomcat.vm.box = "ubuntu/trusty64"
      tomcat.vm.network "private_network" , ip:"192.168.56.12#{i}", :adapter =>2
    end
  end

  (1..2).each do |i|
    config.vm.define "mysql-#{i}" do |mysql|
      mysql.vm.box = "ubuntu/trusty64"
      mysql.vm.network "private_network" , ip:"192.168.56.13#{i}", :adapter =>2
    end
  end

end
相关问题