Vagrant port forwarding stops working after a while - networking

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

Related

vagrant how to access web server (nginx) with public ip

I have tried doing it like this in my vagrantfile
config.vm.network "private_network", ip : "192.168.33.15"
so when I start my box, I could access nginx through my browser 'locally'.
what I want is to access it using public ip. I have tried this, (found in documentation)
config.vm.network "public_network", ip: "202.137.x.x", netmask: "255.255.x.x"
config.vm.provision "shell",
run: "always",
inline: "route add default gw 202.137.x.x"
config.vm.provision "shell",
run: "always",
inline: "eval `route -n | awk '{ if ($8 ==\"eth0\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
this still doesn't work. any ideas?
*edit
I've also tried port forwarding,
config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "202.137.x.x"
I have to do this: 202.137.x.x:8080, I wanted to access without the port. Also, host port cannot be < 1024, so I cannot put port 80..
I've tried doing port forwarding in windows (host), so this is how I solved it..
netsh interface portproxy add v4tov4 listenport=80 listenaddress=202.137.x.x connectport=8080 connectaddress=202.137.x.x
This forwards any requests to the host on port 80 to port 8080 on the host.
So, the port forwarding flow becomes:
host:80 => host:8080 => guest:80
source here

VagrantFile config.vm.network

When my VagrantFile has
config.vm.network :forwarded_port, guest: 9000, host: 9000
I execute the vagrant up statement
Will be displayed.
I thought it was because the post was taken, and I execute netstat -aon , and there is no corresponding port.
If I delete the statement on config.vm.network, Vagrant can be opened normally.
Can someone help me solve it?
It appears to be an issue with the new vagrant 1.9.3 (see https://github.com/mitchellh/vagrant/issues/8395)
you can fix it by adding the host_ip: "127.0.0.1" parameter for each of the "forwarded_port" network configuration.
config.vm.network :forwarded_port, guest: 9000, host: 9000, host_ip: "127.0.0.1"

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

Port forwarding to a VirtualBox image fails after suspend-resume

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

Resources