hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.22k stars 4.43k forks source link

Unable to communicate with host from guest via 10.0.2.2 #13298

Closed ionutantohi closed 9 months ago

ionutantohi commented 10 months ago

10.0.2.2 is the loopback ip which can be used to comunicate with host. I used this in the past but no longer works.

Expected behavior

Host to respond to ping at least

Actual behavior

Unable to comunicate with host over 10.0.2.2

Vagrant version

2.4.0

Host operating system

macOS Sonoma 14.1.1 (23B81)

Guest operating system

Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-87-generic x86_64)

Steps to reproduce

  1. Build a VM using the Vagrant file below
  2. vagrant ssh
  3. ping 10.0.2.2

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.box = 'ubuntu/jammy64'
  config.vm.hostname = 'devbox'
  config.vm.network "public_network", ip: '192.168.0.50', bridge: 'en0: Ethernet'
  config.vm.network "private_network", ip: '192.168.1.50'

  config.vm.provider "virtualbox" do |vb|
    vb.memory = '512'
    vb.cpus = 1
  end
end
chrisroberts commented 9 months ago

Hi there,

The address provided to the guest is not static and is provided via dhcp. The address will be in the 10.0.2.0/24 subnet, but is not guaranteed to be 10.0.2.2. For example:

➜ vagrant up --provider virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/bionic64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/bionic64' version '1.0.282' is up to date...
==> default: Setting the name of the VM: vagrant-test_default_1704384722354_39540
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 6.0.10
    default: VirtualBox Version: 7.0
==> default: Mounting shared folders...
    default: /vagrant => /home/spox/workspace/vagrant-test

➜ vagrant ssh -- ip a | grep 10.0.2
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0

Cheers