简体   繁体   English

公网流浪

[英]Public network in vagrant

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. 我需要使用公共网络设置2个流浪者计算机,因此, 单击此链接以https://www.vagrantup.com/docs/networking/public_network.html编辑Vagrantfile。

But only one machine only have public static ip. 但是只有一台机器只有公共静态IP。 another one not get public static ip. 另一个没有获得公共静态IP。

this is my vagrant machine configuration: 这是我无业游民的机器配置:

Machine 1 Vagrant File: 机器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 File: 机器2流浪文件:

        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

While Vagrant up 无业游民

System Ask Which interface should the network bridge to? 系统询问网络应该桥接到哪个接口?

I Choose Both machie as 1 " eno1 " 我选择两个machie作为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

then, Vagrant ssh Both machine 然后, Vagrant ssh两台机器

only one machine have public static ip , another machine doesn't show public ip. 只有一台计算机具有公共静态IP,另一台计算机不显示公共IP。

if I choose Different Bridge network in any one system some think like: (machine 2) to 如果我在任何一个系统中选择“ 不同网桥”网络 ,则可能会想到:(机器2)

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

option: 4 ( virbro ) ot others now, also same issue. 选项:4( virbro )现在其他,同样的问题。

Update 1: 更新1:

Before I tried Same Setup its working fine, only different Version of Vagrant and VirtualBox 在尝试相同安装程序之前,它只能正常工作,只有不同版本的VagrantVirtualBox

Before Tried: 尝试之前:

Fedrora 23 费德罗拉23

Vagrant 1.8.1 流浪汉1.8.1

virtualbox 5.0 virtualbox 5.0

Now tried: 现在尝试:

Fedrora 23 费德罗拉23

Vagrant 1.8.6 流浪汉1.8.6

Virtualbox 5.1.6 虚拟盒子5.1.6

Any Restrictions in this versions. 此版本中的任何限制。

Why? 为什么?

System cannot share same Bridge network ? 系统不能共享同一网桥网络?

Suggest me how to resolve this problem. 建议我如何解决此问题。

Your Vagrantfile seems good to me. 您的Vagrantfile对我来说似乎很好。 It may be your Machine2 IP 192.168.1.20 is assigned to other system. 可能是您的Machine2 IP 192.168.1.20已分配给其他系统。 if assigned to other system then DHCP will not assign this IP to your machine. 如果分配给其他系统,则DHCP将不会将此IP分配给您的计算机。 if you are sure these IPs not assigned to other system then make it static otherwise you can give like : 如果您确定未将这些IP分配给其他系统,则将其设置为static否则可以这样:

config.vm.network "public_network"

in This case DHCP will release IP that is available. 在这种情况下,DHCP将释放可用的IP。

No need to write separate Vagrantfile for each VM. 无需为每个VM编写单独的Vagrantfile you can create a single Vagrantfile for multiple VM like: 您可以为多个VM创建单个Vagrantfile ,例如:

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

if you want to up server1 then do 如果您想启动server1请执行

vagrant up server1

To up all VM then do 要启动所有VM,然后执行

vagrant up

For ssh use like: 对于ssh使用如下:

vagrant ssh server1

System cannot share same Bridge network ? 系统不能共享同一网桥网络?

yes , it can share bridge network. 是的,它可以共享网桥网络。 you can create multiple VM with single bridge. 您可以使用单个网桥创建多个VM。

For more info you can refer Documentation 有关更多信息,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM