I have a private network VM for developing on my mac. I'd like for my android device to be able to communicate with the VM on my mac. Currently I can visit the IP defined in my Vagrantfile, 10.10.10.10, on my mac and access it just fine but I can't access it via my phone on the same wifi.
What do I need to do to make it available across my local network and visible to my phone over wifi?
Here's my Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :private_network, ip: "10.10.10.10"
config.ssh.forward_agent = true
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--memory", 1024]
v.customize ["modifyvm", :id, "--name", "PHPBoxWith54"]
end
nfs_setting = RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
config.vm.synced_folder "./", "/var/www", id: "vagrant-root" , :nfs => nfs_setting
config.vm.provision :shell, :inline =>
"if [[ ! -f /apt-get-run ]]; then sudo apt-get update && sudo touch /apt-get-run; fi"
config.vm.provision :shell, :inline => 'echo -e "mysql_root_password=root
controluser_password=awesome" > /etc/phpmyadmin.facts;'
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.module_path = "modules"
puppet.options = ['--verbose']
end
end
You are using a Private Network IP which is only accessible by the Host machine (NOT visible to other machines even they are in the same WLAN).
In your case, the best choice is to use Public Network (bridged) so that your Android device can access it.
add config.vm.network "public_network" in your Vagrant file in the config block.
BTW: the default NAT mode is fine but you'll have to set proper port forwarding rules for each service you want to access (e.g. SSH, HTTP, HTTPS etc...).
A little expansion on the accepted answer:
after adding the public network option in your vagrant file and reloading it, ssh into it the old way and then run ifconfig to get the IP you can use to access the vm in your local network from any other device.
Docs: https://www.vagrantup.com/docs/networking/public_network.html
You can easily access your Vagrant from any machine on your network, by simply ensuring that the port forwarding rules aren't bound to your localhost (127.0.0.1).
If you're using VirtualBox as your provider, you can change this on the fly, so you can have it be private by default (which is of course more secure), and then you can go change it in VirtualBox while your VM is running to expose the port to other machines on your network (and possibly the internet, so be careful!)
To expose the port:
Start Virtual Box
Select your VM in the left hand side bar
Click Settings | Network | Advanced | Port Forwarding
Find the port you want to expose in the port list
Set it's Host IP to an empty string, and click OK.
The port is now available to other machines on your network, and possibly the internet, so don't do this unless you're positive you're ok with opening up the port!
Of course to revert it, just do the same process and set the Host IP to 127.0.0.1 again.
This can be just a small problem with port forwarding / setting a dmz. Since it's on the same machine; you can interact since it's physically on the same adapter. However if you are trying to access outside of that, you should try tinkering with the ports.
Related
I have the following Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos/6"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.network :forwarded_port, host: 8080, guest: 80
config.vm.network :forwarded_port, host: 3306, guest: 3306
config.vm.synced_folder "../../applications", "/var/www/html", :owner=>"apache", :group=>"apache"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 2048]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.name = "appserver"
end
end
Each time I run vagrant up (for first time, let's say that first I ran vagrant destroy -f) I end up with the following error:
==> default: Mounting shared folders...
default: /vagrant => E:/Development/vagrant/centos6
default: /var/www/html => E:/Development/applications/arx
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
id -u apache
The error output from the command was:
id: apache: No such user
The error is pretty clear "apache user does not exists". As I am seeing this there is two or "three" ways to fix this:
By removing the :owner=>"apache", :group=>"apache" portion from the synced_folder. This is a BIG no, at least for me because if I remove them then the folder will be owned by vagrant which will/could cause issues while apache tries to read something from /var/www/html.
By commenting the line config.vm.synced_folder, getting up the box so everything gets installed and setup, then shutting down the box and getting up again with the line uncommented: it works but still an ugly solution
By forcing the provisioning to happen before anything gets mounted: the ideal solution.
Does any know if this is possible and if so how? I wasn't able to found anything regarding the 3rd solution :( if you have a better solution you're more than welcome to post here it might help me and others probably.
I have found this and this but is not helpful.
one potential solution would be to run apache as vagrant user.
In your /etc/httpd/conf you can replace the User and Group value as
User vagrant
Group vagrant
so you can continue sharing your folder with vagrant user and httpd will be run as vagrant user.
You can use numeric ids and then create an user
config.vm.synced_folder '${HOSTDIR}', '${EXPORTDIR}', type: "virtualbox", owner: '123', group: '456'
config.vm.provision :shell, inline: "useradd --system -g '456' -u '123' -d '${EXPORTDIR}' --shell /bin/false apache"
I ran into the following error when I execute "vagrant up" command.
The specified host network collides with a non-hostonly network!
This will cause your specified IP to be inaccessible. Please change
the IP or name of your host only network so that it no longer matches that of
a bridged or non-hostonly network.
Vagrant file:
Vagrant.configure("2") do |o|
o.vm.box="centos/7"
o.vm.network "private_network", ip: "192.168.1.13"
o.vm.provision "shell", :path=>"setup.sh"
end
setup.sh:
sudo yum -y update
sudo yum -y install vim,git,gedit,nmap
sudo systemctl restart httpd
Nothing is started but I see a machine in Virtual box and I double click and I start as usual. Could assign static IP but no network to outside world. Not sure where the things are going wrong.
Any help would be very much appreciated.
Thanks
Jim
I'm not sure I've seen that particular error before. However I do have some Vagrant (VirtualBox) VMs that use both a private network to talk to each other, and NAT to talk to the wider world.
I make sure these don't conflict by specifying different private IPv4 network ranges for each. For example:
Vagrant.configure(2) do |config|
# host-only interface address
config.vm.network "private_network", ip: "192.168.0.2"
# NAT interface address range
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--natnet1", "172.16.0.0/12"]
end
end
If I run curl google.com, I can't see the output, only a blank page. My Vagrantfile contains:
Vagrant.configure("2") do |config|
config.vm.box = "trumobi"
#config.vm.box_url = "http://192.168.136.129/package.box"
config.ssh.default.username = "trumobi"
config.vm.network :public_network
config.vm.network :forwarded_port, host: 8000, guest: 8000
end
If you are using Vagrant + VirtualBox + Ubuntu, you might want to add the following block to your VagrantFile:
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
If you are using ubuntu, and you think your firewall is on, here's how you turn off the firewall:
sudo ufw disable
This happens sometimes for me if I switch the host network connection, like disconnecting my laptop Ethernet cable and start using the wireless network.
I found that rebooting the Vagrant vm (vagrant halt, vagrant up) fixes things.
Disabling firewall helped me.
In my CentOS guest box I did:
# sudo service iptables save
# sudo service iptables stop
# sudo chkconfig iptables off
I tried all of the above without success (Vagrant+Virtualbox+Ubuntu 14.04). Virtualbox was showing 'Adapter 1 (NAT): cable disconnected'. Adding the following to my Vagrantfile fixed it:
config.vm.provider 'virtualbox' do |vb|
vb.customize ['modifyvm', :id, '--cableconnected1', 'on']
end
Found here: https://github.com/mitchellh/vagrant/issues/7648
I had created on e box inside vagrant. In the Vagrantfile, I had given the network as
Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network :private_network, ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network :public_network
I can't access the VagrantBox outside the VLAN. I need to access the Vagrant Box in public network. How to configure vagrantfile in such a way that I need to access in public network?
Uncomment the line in Vagrantfile
config.vm.network :public_network
The file will look like below
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "box_name"
config.vm.network :public_network
end
Save it, restart the VM by using vagrant reload.
For VirtualBox, it'll use Bridged mode for networking. Which means the VM will acquire an IP address from the DHCP server for the VLAN.
You can also set the VLAN IP with: config.vm.network :public_network, ip: "192.168.0.160"
Refer to => Public Network
By default, vagrant deletes the default (working) route on additional bridged networks inside the VMs. My problem which was specific for DHCP could only be solved by configuring the bridged network as follows:
config.vm.network :public_network, :bridge => 'em1',:use_dhcp_assigned_default_route => true
Courtesy of https://groups.google.com/forum/#!msg/vagrant-up/yNhWV42pcgk/NbOck1xqtFQJ
There maybe an equivalent for static IPs.
I was unable to figure this out using anything I read (which was hours and hours of research). Instead, this is how I figured it out:
Below is my Vagrantfile. The important part for me was config.vm.network :public_network. After reloading vagrant with vagrant reload, I chose the first option of the 4 available bridged network interfaces (I’m not sure if I chose the correct one by luck, or if any would have worked, I’ll experiment), then sshed into the vagrant box with vagrant ssh, did ifconfig, chose one of the 3 ip addresses that it output, pasted that into my browser, and it worked.
The thing no one else seemed to talk about was sshing into the vagrant box and finding one of the ip addresses there. I hope maybe this helps some other networking newb in the future.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "bahmni-team/bahmni"
config.vm.box_check_update = true
config.ssh.insert_key = false
config.vm.network :public_network
config.vm.synced_folder "..", "/bahmni", :owner => "vagrant"
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", 4092, "--cpus", 2, "--name", "Bahmni-RPM"]
end
end
Finally! This is years later but I couldn't find more current info. For me, the problem was that I not only had a private network defined, but also a forwarded port, and all that was working well. I then commented out the private_network, replaced it with public_network, and couldn't reach anything. Tried everything I found here and elsewhere, no go. It's only when I commented out the port forwarding that things started working again, without any of the manual bridging/dhcp configuration rigamarole suggested.
Single VM environment
you can use command: vagrant ssh
Multi VM environment
you can use command: vagrant ssh {hostname}
I realize this is essentially OSCeption (Operating System Inception), but I think it might make the most sense for me (please tell me if there's a better option, this seems really awful).
Here's the situation:
I have a windows 8 machine. I like it - it works great for everything but development. For development, I've been using a VMWare virtual machine running Ubuntu. I've dabbled with using Cygwin, but it just didn't feel right.
I'm now joining a project where they've been using Vagrant to manage development environments so I need to be able to use Vagrant. But, from what I've seen, Vagrant is mainly used to run code within a consistent environment, but not necessarily to write it. And if I wanted to write code by SSH'ing into my vagrant boxes, then I would have to re-configure my preferences like my .vimrc file and what not for every machine.
Does it then make sense to install Vagrant within my Ubuntu VirtualMachine? I feel like at some point VMs within VMs will get out of hand and cause problems. Is there any better way to do this?
Edit: So I tried it out - as I expected I hit some errors. When I try and boot the machine, I get the following error message:
Failed to open a session for the virtual machine vagranttest_1371583212.
VT-x is not available. (VERR_VMX_NO_VMX).
Result Code: NS_ERROR_FAILURE (0x80004005)
Component: Console
Interface: IConsole {db7ab4ca-2a3f-4183-9243-c1208da92392}
Looks like my vmware virtual machine can't run another virtual machine. Any ideas on the best way to go about doing this?
I've run into the same issue today. The solution is quite simple.
Power off vmware vitrual machine.
Go to "edit virtual machine settings"
Go to processors. There are three checkboxes there.
Check second checkbox (enable VT-x/AMD-V)
Power on machine.
After this virtualbox should work inside vmware.
To answer the original question as well as #blong's Vagrant forum post, this is what I've done to make this work.
I was trying to do something similar myself (actually Vagrant/VMware hosting Vagrant/Vbox) and I have performed all the optimizations I can think of, giving my "host" VM a large amount of RAM (24GB) and 6 cores, disabling swapping VMs to disk (this KILLS things on Windows when it happens) by setting "Fit all VM memory into reserved host memory", and allowing per VM page files (otherwise they live in the system page file which limits how many VMs you can run at once).
What I am doing has been working perfectly, the networking issues I've had were due to the corporate proxy I'm behind. Once I configured that my VM got internet access and all was right with the world.
I did have to manually set --natbindip1 and --natnet1 via the Vagrantfile in addition to the natdnsproxy1 and naddnshostresolver1 that were already set in my example (Virtualbox) Vagrantfile. These settings can be found in the Virtualbox documentation for the correct usage.
To sum it up, use the VT-x passthrough/"virtualize" option in your VM CPU settings, give the VM adequate memory, don't allow that memory to be swapped on the "root" host machine, and try to make sure your network ranges don't overlap or you'll have routing trouble.
Here is the Vagrantfile I was working from, it is based almost entirely on andreptb's gist for the modern.ie vagrant setup. https://gist.github.com/andreptb/57e388df5e881937e62a
# -*- mode: ruby -*-
# vi: set ft=ruby :
# box name into env var, same script can be used with different boxes. Defaults to win7-ie11.
box_name = box_name = ENV['box_name'] != nil ? ENV['box_name'].strip : 'win7-ie11'
# box repo into env var, so private repos/cache can be used. Defaults to http://aka.ms
box_repo = ENV['box_repo'] != nil ? ENV['box_repo'].strip : 'http://aka.ms'
Vagrant.configure("2") do |config|
# If the box is win7-ie11, the convention for the box name is modern.ie/win7-ie11
config.vm.box = "modern.ie/" + box_name
# If the box is win7-ie11, the convention for the box url is http://aka.ms/vagrant-win7-ie11
config.vm.box_url = box_repo + "/vagrant-" + box_name
# big timeout since windows boot is very slow
config.vm.boot_timeout = 500
# rdp forward
config.vm.network "forwarded_port", guest: 3389, host: 3389, id: "rdp", auto_correct: true
# winrm config, uses modern.ie default user/password. If other credentials are used must be changed here
config.vm.communicator = "winrm"
config.winrm.username = "IEUser"
config.winrm.password = "Passw0rd!"
config.vm.provider "virtualbox" do |vb|
# first setup requires gui to be enabled so scripts can be executed in virtualbox guest screen
#vb.gui = true
vb.customize ["modifyvm", :id, "--memory", "1024"]
vb.customize ["modifyvm", :id, "--vram", "128"]
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
end
end
My additional changes:
# Need the WinRM gem for managing from Linux
$ sudo gem install winrm
config.vm.communicator = "winrm"
+ config.winrm.host = "localhost"
config.winrm.username = "IEUser"
config.winrm.password = "Passw0rd!"
# This one may not be necessary, I added it for completeness
+ config.vm.guest = :windows
# In order to USE the two CPUs you need the ioapic
# Virtualbox gives an error in the GUI and only shows 1 CPU in the VM otherwise
vb.customize ["modifyvm", :id, "--cpus", "2"]
+ vb.customize ["modifyvm", :id, "--ioapic", "on"]
# We had to modify the network range because we are running Virtualbox inside VMware
+ vb.customize ["modifyvm", :id, "--natnet1", "192.168.199.0/24"]
Remove the + signs and add those lines into the Vagrantfile above and you should have an equivalent working system to what I've been using.
If you are running virualbox in a VM in vsphere, you have to ssh to the ESXi to update a configuration.
Steps:
ssh to ESXi server.
find the vmx file which belong to your VM find / -name *.vmx
poweroff your VM.(very important, or your change will be overwrite)
edit that vmx, append a new configuration at the bottom of the file: vhv.enable = "TRUE"
power on your VM
enjoy the Vagrant. :)
I have tried this in two VMware products. Right-click on the VM:
In vCloud Director 5.5 VM properties on the Hardware tab there's an "Expose hardware-assisted CPU virtualization to guest OS" checkbox, but it's grayed out for me. YMMV.
In vSphere Version 5.5.0 Edit Settings > Virtual Hardware > CPU the checkbox is called "Expose hardware assisted virtualization to the guest OS," and that worked for me.