Port forwarding to a VirtualBox image fails after suspend-resume - networking

We use vagrant to setup a VirtualBox image with Ubuntu Linux. It has private network enabled, and a number of ports are forwarded - here are some snippets from our Vagrantfile:
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.network "forwarded_port", guest: 3306, host: 3306 #mysql
...
config.vm.network "forwarded_port", guest: 8098, host: 8098 #riak http
config.vm.network "forwarded_port", guest: 8087, host: 8087 #riak pb
This works allright when the VM is started.
But after the host machine has been suspended for a while (more than a brief period) and resumes, then the port forwarding does not work any more.
Everything responds fine on the allocated private network address, 192.168.33.10, but not on localhost where the attempt just hangs.
Any ideas for a solution?
Specs:
Host OS: Mac OS X, version 10.9 "Mavericks"
Guest OS: Ubuntu 12.04, precise64 (standard box from vagrantup.com)
Vagrant 1.4.0
VirtualBox version: VirtualBox 4.3.4 r91027
Virtual Box > Machine Settings > Network
Adapter 1:
Attached to: NAT
Cable Connected : True
Port Forwarding:
TCP, HostIP=, HostPort=3306, GuestIP=, GuestPort=3306
TCP, HostIP=, HostPort=8098, GuestIP=, GuestPort=8098
TCP, HostIP=, HostPort=8087, GuestIP=, GuestPort=8087
TCP, HostIP=127.0.0.1, HostPort=2222, GuestIP=, GuestPort=22
I found a similar question, but can not seem to use the same answer: VirtualBox port forwarding not working with NAT adapter

Related

How to know the forwarding port

I have brought a VM using vagrant.In the config vagrant file, I have given
config.vm.network "forwarded_port", guest: 830, host: 8300.
I'm able to ssh in to the VM by
ssh -p 2223 vagrant#localhost
What if i want to spawn multiple VMs of same kind.How to configure the forwarding ports
You can use auto_correct parameter (see https://www.vagrantup.com/docs/networking/forwarded_ports.html); in case of port collision vagrant can assign another port
config.vm.network "forwarded_port", guest: 830, host: 8300, auto_correct: true
you can check vagrant port to displays information about guest port mappings. The command makes a warning about the value
The forwarded ports for the machine are listed below. Please note that
these values may differ from values configured in the Vagrantfile if
the provider supports automatic port collision detection and
resolution.
just use vagrant ssh to ssh-in into the VM, vagrant will know which port to use.

Vagrant port forwarding stops working after a while

I am using an ubuntu provisioned vagrant vm to sun a service. Here is the vagrant file
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.provision "file", source: "/opt/artifactory-pro-4.11.1", destination: "/opt/"
config.vm.network "forwarded_port", guest: 80, host: 70
config.vm.network "forwarded_port", guest: 8081, host: 7081
end
I then try to access the service at "localhost:7081" I can access it for sometme but then it becomes unavailable. I've tried to configure the host_ip as
host_ip = 127.0.0.1 and host_ip = 0.0.0.0
But the problem still persists
I tried destroying the VM and running the service on different ports but no luck

How do you create a host-only network in Vagrant for NFS?

I cannot find any information in the docs about this error message:
NFS requires a host-only network to be created.
Please add a host-only network to the machine (with either DHCP or a
static IP) for NFS to work.
Here is my Vagrant config:
Vagrant.configure(2) do |config|
config.vm.box = "localbox"
config.vm.network "public_network", hostonly: "192.168.33.10"
config.vm.synced_folder ".", "/var/www",
:nfs => true,
:mount_options =>['noacl,nolock,vers=3,udp,noatime,nodiratime,rsize=32768,wsize=32768']
When asked, I pick my Airport connection for the bridge (Wi-Fi (AirPort)).
I cannot find a single usage of hostonly in the Vagrant docs.
Using Vagrant 1.7.4
My goal is simply to be able to access the VM running on one computer in my house, from other computers (and my phone) in my house.
If you want to have NFS and Public/bridge network try this:
Vagrantfile
config.vm.network "private_network", ip: "192.168.10.100"
config.vm.network "public_network", ip: "192.168.20.200"
or
config.vm.network "private_network", ip: "192.168.10.100"
config.vm.network "public_network", ip: "192.168.20.200", bridge: "en1: Wi-Fi (AirPort)"
Replace hostonly by ip in your Vagrantfile
config.vm.network "public_network", ip: "192.168.33.10"

connection refused from host machine

I am using vagrant with virtualbox as provider. Within my guest system I have nginx installed and configured.
nginx is serving some static files from a folder and exposing them on port 80. That works fine. If I call curl localhost within the guest machine I get the answer I was supposed to receive.
I have a very simple vagrantfile, which you can see below. I forward port 80 to port 8080, but from the host machine I cant access that page via localhost:8080.
I already disabled the firewall in the guest machine without any success.
Vagrant.configure("2") do |config|
# VirtualBox Settings: Give it a little bit more memory
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "768"]
end
# Base Image: CentOS 7.0 x86_64
config.vm.box = "jayunit100/centos7"
# Use Vagrant's default insecure key (~/.vagrant.d/insecure_private_key)
config.ssh.insert_key = false
# Add port forwarding for node-inspector
config.vm.network :forwarded_port, guest: 80, host: 8080 # node-inspector
# Map project directory
config.vm.synced_folder ".", "/server/"
# Provisioning Shell Script
config.vm.provision :shell, :path => "vagrant-setup/base.sh"
end
If I call curl -v 'http://localhost:8080' from the host system I get told that the connection got refused. Any idea what I could do?
I had to disable my firewall on the host machine with iptables -F

browser in host can not see vagrant box, portforward does not work

I have installed Vagrant in my Window XP, and in my Vagrantfile I have:
Vagrant::Config.run do |config|
# Setup the box
config.vm.box = "lucid32"
config.vm.forward_port 80, 8080
config.vm.network :hostonly, "192.168.10.200"
end
But I see no sign of my vagrant box when I type "http://192.168.10.200:8080" in browser.
IP address of the virtual box is correct, because from within the vbox, I have:
vagrant#lucid32:~$ ifconfig
....
eth1 Link encap:Ethernet HWaddr 08:00:27:79:c5:4b
inet addr:192.168.10.200 Bcast:192.168.10.255 Mask:255.255.255.0
There seem to be no firewall problem because if I type
vagrant#lucid32:~$ curl 'http://google.com'
it works fine.
I have read Vagrant's port forwarding not working
and tried:
vagrant#lucid32:~$ curl 'http://localhost:80'
curl: (7) couldn't connect to host
and also
vagrant#lucid32:~$ curl 'http://localhost:8080'
curl: (7) couldn't connect to host
So, looks like port forward is not working...
If you know what I can do so I can access my vbox from host browser, can you help me?
Thanks in advance
If you just started a Vagrant box with this Vagrantfile, there is nothing more than an empty Ubuntu Lucid, which does not run any service yet. So there is nothing served on port 80, this is why there is nothing to see either from inside the box on port 80 or the host machine on 8080.
For you Vagrant machine to provide some services (such as a web server on port 80), you have to do some provisioning. You can do it manually or using Chef or Puppet which are hooked into Vagrant's up process.
I had a similar problem. Sometimes using port forwarding for ports below 2000 is a problem. What worked for me is choosing ports that are above 2000. So my vagrantfile now looks like:
config.vm.network :forwarded_port, host: 4500, guest: 9000
Typing localhost:4500 on my host machine now just works fine. It seems like you are on an older version of vagrant than mine, so you can edit your vagrant file to something like
config.vm.forward_port 9000, 4500
Now typing localhost:4500 on your host machine should work fine.
Good luck,

Resources