VagrantFile config.vm.network - networking

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"

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

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

BrowserSync with Vagrant, Zurb Foundation, Nginx, Gulp

I seem to be close after a couple of days deep into this setup but still can't get BrowserSync to use Nginx as the server on the Vagrant Ubuntu 14.04 with Nginx guest and view the html on my MacBook Pro host. However, on http://localhost:3001/ on my Mac Chrome browser I can view a BrowserSync page with settings and such. Therefore I suspect I'm doing something right, but probably not much.
I expect to see the Foundation splash page but I get "This site can’t be reached". Before I modify the gulpfile I can view the splash page with localhost:8079, the usual setup, so Foundation is working correctly.
I've tried localhost: 3000, 3001, and 3002 and those ports with the Vagrant IP 10.0.2.15 and 127.0.0.1 and 0.0.0.0. Anyone have a setup that works with this stack? I couldn't find a discussion anywhere with this setup.
The relevant parts of my gulpfile. I'm modifying what Foundation for Apps sets up.
var browserSync = require('browser-sync').create();
I got this code off a forum. I also tried other similar configs. I've commented out the Foundation server setup because I want to develop with Nginx. My limited understanding it that if I use the "server" in BrowserSync that I'll get a little dev server like Foundation's.
gulp.task('browser-sync', function() {
browserSync.init({
proxy: 'localhost:3002'
});
});
At the bottom of the Gulpfile we do the watch thingy.
gulp.task('default', ['browser-sync'], function () {
// Watch Sass
gulp.watch(['./client/assets/scss/**/*', './scss/**/*'], ['sass']);
...
After running "foundation watch" I get this:
[BS] Proxying: http://localhost:3002
[BS] Access URLs:
----------------------------------
Local: http://localhost:3000
External: http://10.0.2.15:3000
My Vagrantfile has port forwarding. The first three work as expected.
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", host: 8080, guest: 80
config.vm.network "forwarded_port", host: 8079, guest: 8079
config.vm.network "forwarded_port", host: 1337, guest: 1337
config.vm.network "forwarded_port", host: 3000, guest: 3000
config.vm.network "forwarded_port", host: 3001, guest: 3001
config.vm.network "forwarded_port", host: 3002, guest: 3002
config.vm.host_name = "sails"
config.vm.provision :shell, path: ".provision/bootstrap.sh"
config.vm.provision "file", source: "~/.gitconfig", destination: "~/.gitconfig"
This URL also works to see the Foundation splash page which is served by Nginx. I haven't studied Nginx yet but one step at a time. I'll have to figure out how to setup the servers for static and dynamic files.
Appreciate help of course. I put my Vagrant setup files here if anyone with this stack wants a shortcut to a great dev environment: https://github.com/svstartuplab/Vagrant-Foundation-Sails-Nginx

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