Head
Head

Reputation: 568

localhost Vagrant and VM on a windows (8.1) build - vagrant file specifications

Having a problem getting my localhost to work properly.

Running git bash I've successfully vagrant init "hashicorp/precise32"

vagrant up

Perhaps I'm putting my local host IP in the wrong place: 127.0.0.1

Confirmed my VM is running and here is my vagrant file:

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

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!

Vagrant.configure(2) do |config|

  config.vm.box = "hashicorp/precise32"

  # config.vm.boot_timeout = "300"
  # Setting this above never worked for me when i had a config.vm.boot_timeout

  config.vm.network :forwarded_port, guest: 80, host: 8082

  # config.vm.network :public_network
  config.vm.network "private_network", ip: "127.0.0.1"

  config.vm.synced_folder ".", "/vagrant", type: "nfs"


  config.vm.provider :virtualbox do |vb|
    vb.gui = true

# I turned this vb.gui = true on when i was having a problem with config.vm.boot_timeout

    vb.customize ["modifyvm", :id, "--memory", "4096"]
    vb.cpus = 4

  end

end

I've added some additional options but I think my ip or ports are wrong. Any help would be greatly appreciated. Thank you.

edit ************************

Host file looks like so:

# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handle within DNS itself.
       127.0.0.1       localhost
       ::1             localhost

After I vagrant reload:

$ vagrant reload
==> default: [vagrant-hostsupdater] Removing hosts
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'hashicorp/precise32' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 (guest) => 8082 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> 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: Machine booted and ready!
[default] GuestAdditions 5.1.8 running --- OK.
==> default: Checking for guest additions in VM...
==> default: [vagrant-hostsupdater] Checking for host entries
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/Timothy/Documents/Magento
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

Why is this so confusing right now, I've never had so much trouble setting up a local dev. environment.

Upvotes: 1

Views: 349

Answers (1)

Frederic Henri
Frederic Henri

Reputation: 53793

you cannot use a private_network of 127.0.0.1 from your host thats your loopback adapter so it will never be able to reach your VM.

You should use on of the 3 following ranges (see https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces)

  • 10.0.0.0 - 10.255.255.255
  • 172.16.0.0 - 172.31.255.255
  • 192.168.0.0 - 192.168.255.255

vagrant will already create a NAT adapter on 10.0.2.15 to communicate over ssh.

I suggest to take an IP in the 192.168.x.x range and you will be able to work correctly with your VM

Upvotes: 1

Related Questions