Vagrant can't assign static ip to box - vagrant

I have the following inside my Vagrant file.
config.vm.network "private_network", ip: "192.168.33.12"
When I "vagrant up", vagrant is assigning 127.0.0.1. I'm not sure what's causing this. Below is the full trace.
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> 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: 22 (guest) => 2200 (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:2200
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => C:/vm2
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

what you see here
default: SSH address: 127.0.0.1:2200
is not your VM IP address - this is just for vagrant to ssh into the box using an available port (in your case 2200). vagrant configures on your VM the eth0 interface to communicate with the host
Login to the VM and run ifconfig you will see you have (at least) 2 interfaces available with eth0 on 10.0.2.15 and eth1 on 192.168.33.12

As a shorthand way of doing this, a oneliner you can run from the host to see assigned IPs on the guest:
$ vagrant ssh -c "ifconfig | grep 'inet addr'"
Which will give you an output like this:
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet addr:192.168.200.200 Bcast:192.168.200.255 Mask:255.255.255.0
inet addr:127.0.0.1 Mask:255.0.0.0

Here are the steps that i choose while setting up the static ip of the Ubuntu machine:
ls /etc/netplan/ //go to this directory to find the config file
Note: the YAML file is very strict about the indentations e.g
dhcp4:true //will give wrong indentation error
dhcp4: true //right way to give
Now edit the config file:-
sudo nano /etc/netplan/01-netcfg.yaml
Change Default settings from :-
network:
version: 2
renderer: networkd
eth0:
dhcp4: true
dhcp6: false
optional: true
nameservers:
addresses: [8.8.8.8,8.8.4.4]
To
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [172.28.32.11/16] //here choose your desired IP
gateway4: 172.28.32.1 //provide the gateway address,
nameservers:
addresses: [8.8.8.8,8.8.4.4]
Now do :
sudo netplan apply // to apply the network settings
You can then check that the ip address remains same during any course between vagrant halt/up

Here is what i did for the virtual box set machine of vagrant:
Add this to to vagrant file :-
config.vm.network "private_network", ip: "any IP address that you choose"
Then do the Vagrant Reload and you should be good.
In case the VM stucks for Vagrant Up command in retrying the connect or ssh .. do this:-
Run the below command from the cmder console:-
vagrant plugin install vagrant-vbguest
After this enable Vagrant GUI by adding the following to the vagrant file:-
config.vm.provider :virtualbox do |vb|
vb.gui = true
end
Now do the vagrant up
the vagrant gui window will open and Keep Pressing "S" to skip and enter the login screen
Login with the username/password which is root/vagrant by default
and run the following command:-
sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
Now come out of the vagrant gui window shell and
remove the line added earlier for enabling the vagrant gui
from the cmder console do "vagrant up" again
Done!

Related

vagrant ssh get error: ssh_exchange_identification: read: Connection reset by peer

I'm installing buildroot. But when I fllow the manual from buildroot doc, the error occurred.
This is my process.
curl -O https://buildroot.org/downloads/Vagrantfile; vagrant up
And the results are as fllows.
==> default: Attempting graceful shutdown of VM...
default: Guest communication could not be established! This is usually because
default: SSH is not running, the authentication information was changed,
default: or some other networking issue. Vagrant will force halt, if
default: capable.
==> default: Forcing shutdown of VM...
==> default: Checking if box 'ubuntu/bionic64' 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: Forwarding ports...
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
Then I try to connect with ssh
vagrant ssh
But there is northing to show. Just like this.
lt#ubuntu:~/qemu/buildroot$ vagrant ssh
So I try ssh command.
lt#ubuntu:~/qemu/buildroot$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/lt/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
ssh vagrant#127.0.0.1 -p 2222 i /home/lt/.vagrant.d/insecure_private_key
However, also northing to show.
Could you give me a sultion? Thanks.
Try performing the following commands:
vagrant halt
vagrant up
vagrant ssh
This should fix the issue. If it still persists, check your bios settings to ensure that virtualization is enabled. If your on windows, make sure hyper-v is disabled.
Its a duplicate question and answered multiple times
You can refer my answer here https://stackoverflow.com/a/62928259/6150566
Enable Virtualization by going to BIOS if you are on Windows.
If you are running VirtualBox inside a nested VM, you can enable the Virtualization settings (VT-X) by powering off the VM.

Configuration issue with OpenShift3 origin/all-in-one, vagrant Cluster setup

I am facing issue to see login page at
https://10.2.2.2:8443/console
,
even when I trying to do
"oc login https://10.2.2.2"
It worked for the first installation and I was able to login, but I had no luck when I did few re-installations to customize.
I have already gone throgh existing github vagrant issues, and stackoverflow as well but no clues for this issue.
I appreciate if someone can help me with this issue.
Installations Detals:
I've followed this blog for cluster setup in my mac ,
1) Installed VirtualBox Version 5.1.14 r112924 (Qt5.6.2)
2) Installed Vagrant 1.9.1
Here is my Vagrantfile config,
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.require_version ">= 1.7.2"
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version. Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
config.vm.box = "openshift/origin-all-in-one"
# uncomment this line if you downloaded the box and want to use it instead
# config.vm.box = "openshift3"
config.vm.box_check_update = false
config.vm.network "private_network", ip: "10.2.2.2"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.hostname = "origin"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "forwarded_port", guest: 80, host: 1080
# config.vm.network "forwarded_port", guest: 443, host: 1443
# config.vm.network "forwarded_port", guest: 5000, host: 5000
# config.vm.network "forwarded_port", guest: 8080, host: 8080
# config.vm.network "forwarded_port", guest: 8443, host: 8443
config.vm.provider "virtualbox" do |vb|
# vb.gui = true
vb.memory = "4096"
vb.cpus = 2
vb.name = "origin-1.3.0"
end
end
This is my debug logs for Vagrant up --debug
Last login: Wed Feb 1 13:59:59 on ttys000
xxxxxs-MBP:origin xxxxx$ vagrant init openshift/origin-all-in-one
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
xxxxxs-MBP:origin xxxxx$ vagrant up --provider=virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'openshift/origin-all-in-one' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'openshift/origin-all-in-one'
default: URL: https://atlas.hashicorp.com/openshift/origin-all-in-one
==> default: Adding box 'openshift/origin-all-in-one' (v1.3.0) for provider: virtualbox
default: Downloading: https://atlas.hashicorp.com/openshift/boxes/origin-all-in-one/versions/1.3.0/providers/virtualbox.box
==> default: Successfully added box 'openshift/origin-all-in-one' (v1.3.0) for 'virtualbox'!
/Users/xxxxx/.vagrant.d/boxes/openshift-VAGRANTSLASH-origin-all-in-one/1.3.0/virtualbox/include/_Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION
/Users/xxxxx/origin/Vagrantfile:5: warning: previous definition of VAGRANTFILE_API_VERSION was here
==> default: Importing base box 'openshift/origin-all-in-one'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: origin-1.3.0
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
default: Adapter 3: hostonly
==> default: Forwarding ports...
default: 8443 (guest) => 8443 (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: Warning: Remote connection disconnect. Retrying...
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: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Running provisioner: shell...
default: Running: inline script
==> default:
==> default: Successfully started and provisioned VM with 2 cores and 5 G of memory.
openshift.service in vm is failing to start automatically,
I did ssh to machine and started manually with command sudo systemctl start origin and everything working perfect.
I had a bit of issue with Origin myself. I ended up using Docker and OpenShift Client. I have written down step by step on how to get started with OpenShift Origin on Windows. I am not trying to promote anything here. The entry is too long for me to cut and paste it. Please visit the link below:
http://blog.muralibala.com/2017/01/getting-started-with-openshift-origin-on-windows/
Hope this is helpful.

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.
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

Laravel homestead and vagrant setup not working

I followed the original documentation for vagrant and homestead but every site.app:8000 you visit it just keeps loading and nothing happens. Is there an error within this configuration files?
Homestead.yaml
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Developer/laravel
to: /home/vagrant/laravel
sites:
- map: hello-world.local
to: /home/vagrant/laravel/hello-world/public
databases:
- homestead
hosts
192.168.10.10 hello-world.local
vagrant up log
Bringing machine 'default' up with 'virtualbox' provider...
==> 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) => 8000 (host) (adapter 1)
default: 443 (guest) => 44300 (host) (adapter 1)
default: 3306 (guest) => 33060 (host) (adapter 1)
default: 5432 (guest) => 54320 (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: 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: 5.0.20
default: VirtualBox Version: 5.1
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/nikla/Developer/homestead
default: /home/vagrant/laravel => /Users/nikla/Developer/laravel
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
nmap log
Starting Nmap 7.12 ( https://nmap.org ) at 2016-07-29 22:55 ART
Nmap scan report for 192.168.10.10
Host is up (0.00063s latency).
Not shown: 994 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
3306/tcp open mysql
5432/tcp open postgresql
9000/tcp open cslistener
Nmap done: 1 IP address (1 host up) scanned in 13.19 seconds
I have check your "vagrant up" log and I see all things ok. I have compared your log with my machine's log and is similar.
Try to open the IP in the web browser (change the IP with your Vagrant VM IP):
http://192.168.10.10/
Do you have some firewall, antivirus or another software that could disable the communication?
Try to execute a nmap to see wich ports are open. I paste my nmap, from my host machine to my virtual machine, so you can see wich ports are open.
$ nmap 192.168.10.10
Starting Nmap 6.47 ( http://nmap.org ) at 2016-07-30 01:48 Hora de verano romance
Nmap scan report for homestead.app (192.168.10.10)
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
Host is up (0.0019s latency).
Not shown: 993 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
111/tcp open rpcbind
443/tcp open https
3306/tcp open mysql
5432/tcp open postgresql
9000/tcp open cslistener
MAC Address: 08:00:27:CD:99:8C (Cadmus Computer Systems)
Nmap done: 1 IP address (1 host up) scanned in 21.83 seconds
Check:
The id_rsa.pub and the id_rsa are in this folder.
The /Users/nikla/Developer/laravel folder exists in your host machine.
The /home/vagrant/laravel exists in your Vagrant VM machine. You can check it login in the machine using the command "vagrant ssh".
Try to access to the http://test.app without the 8000 port.
I don't see the database in your Homestead.yaml file. You should have the next text in this file
databases:
- homestead

Vagrant sync folder doesn't work on windows 10

I'm trying to sync folders from a windows 10 hosto to a ubuntu guest but I get this error:
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/trusty64' 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: Forwarding ports...
default: 8080 (guest) => 8080 (host) (adapter 1)
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: Warning: Remote connection disconnect. Retrying...
default: Warning: Remote connection disconnect. Retrying...
==> 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: 4.3.36
default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
default: /vagrant => C:/sync_workspace
default: /sync_workspace => C:/sync_workspace
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3`,nolock,vers=3 core /sync_workspace
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant`,nolock,vers=3 core /sync_workspace
The error output from the last command was:
stdin: is not a tty
unknown mount option `nolock'
valid options:
rw mount read write (default)
ro mount read only
uid =<arg> default file owner user id
gid =<arg> default file owner group id
ttl =<arg> time to live for dentry
iocharset =<arg> i/o charset (default utf8)
convertcp =<arg> convert share name from given charset to utf8
dmode =<arg> mode of all directories
fmode =<arg> mode of all regular files
umask =<arg> umask of directories and regular files
dmask =<arg> umask of directories
fmask =<arg> umask of regular files
Here is my Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.synced_folder "C:/Users/rafa/Documents/personal docs", "/vagrant_data/sync_workspace"
end
Host : Windows 10
Guest: Ubuntu
Vagrant: 1.8.1
VirtualBox : Version 5.0.20 r106931
Any Help?
Install the vagrant vaguest plugin and let it install the host's VirtualBox Guest Additions on the guest system and in your case it will update your guest addition
Also try apt-get update in your guest OS.

Resources