流浪汉中的公共网络 [英] Public network in vagrant

查看:686
本文介绍了流浪汉中的公共网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用公共网络设置2个流浪汉机器,因此请点击此链接 https: //www.vagrantup.com/docs/networking/public_network.html 编辑Vagrantfile。

I Need to setup 2 vagrant machine with public network,so follow this link to https://www.vagrantup.com/docs/networking/public_network.html edit the Vagrantfile.

但只有一台机器只有公共静态IP。另一个获取公共静态IP。

But only one machine only have public static ip. another one not get public static ip.

这是我的流浪汉机器配置:

this is my vagrant machine configuration:

机器1流动文件:

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

      config.vm.box = "man2"

      config.ssh.username = "vagrant"
      config.vm.hostname = "www.myhost.net"
      config.ssh.forward_agent = "true"


      config.vm.network "public_network", ip: "192.168.1.10"

      config.vm.provider :virtualbox do |vb|
        vb.customize ["modifyvm", :id, "--memory", "2048"]
      end
      config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"] 
    end

Machine 2 Vagrant文​​件:

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

          config.vm.box = "man1"
          config.ssh.username = "vagrant"
          config.vm.hostname = "www.myhost.net"
          config.ssh.forward_agent = "true"

         config.vm.network "public_network", ip: "192.168.1.20"

           config.vm.provider :virtualbox do |vb|
            vb.customize ["modifyvm", :id, "--memory", "2048"]
          end

           config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=777"]

        end

虽然 Vagrant up

系统询问网络应该连接哪个接口?

我选择两个机器人为1 eno1

        1) eno1
        2) docker0
        3) veth54294ac
        4) virbr0
        5) vethc81d7f7
        6) br-08179b343476
        7) br-1d45dec94893
        ==> default: When choosing an interface, it is usually the one that is
        ==> default: being used to connect to the internet.
            default: Which interface should the network bridge to? 1

然后, Vagrant ssh 两台机器

只有一台机器有公共静态IP,另一台机器没有显示公共IP。

only one machine have public static ip , another machine doesn't show public ip.

如果我选择不同的网络网络在任何一个系统中有些人认为:(机器2)到

if I choose Different Bridge network in any one system some think like: (machine 2) to

        1) eno1
        2) docker0
        3) veth54294ac
        4) virbr0
        5) vethc81d7f7
        6) br-08179b343476
        7) br-1d45dec94893

选项:4( virbro )其他人现在也是同样的问题。

option: 4 (virbro) ot others now, also same issue.

更新1:

在我尝试使用Same Setup之前,它的工作正常,只有不同版本的 Vagrant VirtualBox

Before I tried Same Setup its working fine, only different Version of Vagrant and VirtualBox

尝试之前:

Fedrora 23

Fedrora 23

Vagrant 1.8.1

Vagrant 1.8.1

virtualbox 5.0

virtualbox 5.0

现在尝试过:

Fedrora 23

Fedrora 23

Vagrant 1.8.6

Vagrant 1.8.6

Virtualbox 5.1.6

Virtualbox 5.1.6

此版本中的任何限制。

为什么?

系统无法共享同一个Bridge网络?

System cannot share same Bridge network ?

建议我如何解决这个问题。

Suggest me how to resolve this problem.

推荐答案

您的 Vagrantfile 对我来说似乎不错。可能是您的 Machine2 IP 192.168.1.20 已分配给其他系统。如果分配给其他系统,则DHCP不会将此IP分配给您的计算机。
如果您确定这些IP未分配给其他系统然后使其静态否则您可以给出:

Your Vagrantfile seems good to me. It may be your Machine2 IP 192.168.1.20 is assigned to other system. if assigned to other system then DHCP will not assign this IP to your machine. if you are sure these IPs not assigned to other system then make it static otherwise you can give like :

config.vm.network "public_network"

in这种情况DHCP将释放可用的IP。

in This case DHCP will release IP that is available.

无需为每个VM单独编写 Vagrantfile 。你可以为多个虚拟机创建一个 Vagrantfile ,如:

No need to write separate Vagrantfile for each VM. you can create a single Vagrantfile for multiple VM like:

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

    config.vm.define :server1 do |server1|
             server1.vm.box = "man1"      
             server1.vm.host_name = "vm1.example.com"
             server1.vm.network "public_network", ip: "192.168.1.10"
             server1.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
             server1.vm.provider :virtualbox do |vb|
                   vb.customize ["modifyvm", :id, "--memory", "2048"]
            end    
    end

    config.vm.define :server2 do |server2|
             server2.vm.box = "man1"      
             server2.vm.host_name = "vm2.example.com"
             server2.vm.network "public_network", ip: "192.168.1.20"
             server2.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777","fmode=666"]
             server2.vm.provider :virtualbox do |vb|
                   vb.customize ["modifyvm", :id, "--memory", "2048"]
            end
    end
end

如果你想要 server1 那么

vagrant up server1

启动所有VM然后做

vagrant up

对于ssh使用如:

vagrant ssh server1




系统无法共享同一个Bridge网络?

System cannot share same Bridge network ?

是的,它可以共享桥接网络。您可以使用单桥创建多个VM。

yes , it can share bridge network. you can create multiple VM with single bridge.

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

For more info you can refer Documentation

这篇关于流浪汉中的公共网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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