Allow two or more vagrant VMs to communicate on their own network

前端 未结 1 736
别跟我提以往
别跟我提以往 2021-02-05 08:36

I want to create multiple servers that can communicate directly with each other without using public IPs. They\'ll still need internet access but nothing from outside the networ

1条回答
  •  无人及你
    2021-02-05 09:07

    Here's an example which creates two VMs:

    • alpha 10.0.0.10
    • beta 10.0.0.11

    From inside either VM you can reach the other by IP address, and can connect to the outside world.

    Vagrantfile:

    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    
    # Vagrant multi-machine sample setup
    
    Vagrant.configure("2") do |config|
      config.vm.define :alpha do |alpha|
        alpha.vm.box = "hashicorp/precise64"
        alpha.vm.network :private_network, ip: "10.0.0.10"
        alpha.vm.hostname = "alpha"
      end
    
      config.vm.define :beta do |beta|
        beta.vm.box = "hashicorp/precise64"
        beta.vm.network :private_network, ip: "10.0.0.11"
        beta.vm.hostname = "beta"
      end
    end
    

    0 讨论(0)
提交回复
热议问题