1

I am trying to build a k3s cluster. To test my Ansible setup script, I want to set up a small sandbox with vagrant.

However I can't figure out how to communicate between two VMs.

The Vagrantfile I have is this:

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

  config.vm.box = "ubuntu/noble64"

  servers = [
    { :name => "master1", :ip => "192.168.56.2" },
    { :name => "master2", :ip => "192.168.56.3" },
  ]

  servers.each do |opts|
    config.vm.define opts[:name] do |server|
        server.vm.hostname = opts[:name] + "k3s"
        server.vm.network "private_network", ip: opts[:ip]
        server.vm.provider :virtualbox do |vb|
          vb.name = opts[:name] + "k3s"
          vb.gui = false
          vb.memory = 1024
          vb.cpus = 2
          vb.linked_clone = true
        end
    end
  end

As far as I understand the Vagrant documentation, both machines should be able to communicate through their assined ips. ip add show Shows me that both machines have the IP I assigned to them.

But when running tcpdump ip proto \\icmp on one machine and ping ... from the other I don't see any incoming pings.

Is there something I am missing for both machines to be able to communicate?

4
  • Make sure you did not set the Guest machines up as Host Only.
    – anon
    Commented Jan 25 at 14:07
  • I see it's host only, what should I switch it to? There is NAT, bridged adapter, internal network, and NAT network
    – iaquobe
    Commented Jan 25 at 14:10
  • Try the NAT adapter
    – anon
    Commented Jan 25 at 14:15
  • after using the NAT, ping reported destination unreachable. However I found out, tcpdump was listening to the wrong interface. So communication works. Thanks :)
    – iaquobe
    Commented Jan 25 at 14:26

1 Answer 1

1

For Virtual Box guests, guest machines connect using NAT or Bridged networking. That is the easiest way.

It may be possible to connect to Host Only machines, but it it is much more complicated to do.

Make sure your host-only networks are unique (at least any that are participating in the scheme). That is, each host-only network needs to be different, and not all the same default 192.168.56.0/24 network. .

.... you could choose to use other 10.x.y.0/24 networks (you've got about 64K choices!) for your host-only networks. (Note that since your example gateway isn't on your network, it suggests your network is really 10.0.0.0/8, so be wary of other potential conflicts.) Of course, you can continue to use the 192.168.y.0/24 networks, too, but make sure each host-only network uses a different "y" value. .

Configure your guests to have routes off the host-only network through the host's host-only network IP. Unlike the NAT virtual networks, the host-only DHCP server doesn't provide guests with routing information, just addresses.

This can be done a variety of ways, like replacing the DHCP server, but essentially all you have to do is tell each guest OS how to get off of the host-only network. For most OS' it's the same command (which requires administrative powers):

Source: Connect Host Only Machines

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .