Vagrant port forwarding not working on Mavericks - macos

I'm using a vagrant Geodjango box and port forwarding is not working for me.
On the box, I have run:
python manage.py runserver 0.0.0.0:8000
But http://localhost:8000 and http://localhost:4567 both find nothing on the host machine.
On the Vagrant box, curl -v 'http://localhost:8000/' gives the usual:
<h2>Congratulations on your first Django-powered page.</h2>
which suggests that Django is running okay. But on the host machine, trying curl -v 'http://localhost:8000/' gives the following output:
curl: (7) Failed connect to localhost:8000; Connection refused
My Vagrantfile has the following port forwarding set up:
config.vm.forward_port 8000, 4567
Disabling the Mac's firewall does not help and stopping Apache makes no difference. I have tried running lsof -i :8000 on the host machine and there is no output, so I figure nothing is using the port.
Can anyone suggest anything?

I had the same issue on Yosemite and none of the ports were forwarding. Disabling the Firewall filter on the guest machine helped:
sudo service iptables stop

Good to see you figured it out yourself.
Just want to add my 2 cents, in V2 Vagrantfile, the port forwarding code block is like below, try to use the new ones so as to avoid port conflicts (back in v1 I always got confused which is which).
config.vm.forward_port 8000, 4567 is forwarding guest port 8000 to host 4567, not the other way around.
In V2 format, it looks like below, which is clearer from my opinion
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 80, host: 8080
end

Related

Vagrant - vagrant cannot forward the specified ports on this VM

When i run vagrant up i get the following error:
Vagrant cannot forward the specified ports on this VM, since they
would collide with another VirtualBox virtual machine's forwarded
ports! The forwarded port to 3306 is already in use on the host
machine.
To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.forward_port 80, 1234
I checked and i don't have any processes using port 3306 locally.
I also tried vagrant destroy and vagrant up, didn't help.
vagrant suspend followed by vagrant resume didn't help as well.
What else could be the issue?
What's your command to find the port?
Maybe you can see this. Vagrant Port Collision on Port 80, but Port 80 is not Forwarded in the VagrantFile
Turns out there was a process on my machine running on port 3306.
Running lsof -i :3306 didn't show it, only when i used sudo it did.

Cannot access application running on JBOSS EAP 7 outside vagrant box

I am actually trying to access the application outside the vagrant box which is running on JBOSS EAP 7 server on port 8080. I did add the settings for port forwarding in vagrant file that is
config.vm.network :forwarded_port, guest: 3000, host: 8080
Port forwarding does shows in terminal log when i reloaded the vagrant. However when i access the application from browser outside of the vagrant box am getting error as ERR_CONNECTION_REFUSED on the browser. I also binded the address to 0.0.0.0 by running the below command but still no luck. Any suggestions please what i may be missing? I also did set the proxy settings but still no luck.
sudo ./standalone.sh -b 0.0.0.0
Below is the port binded with 0.0.0.0
Below is the log for my vagrant reload
Below is the port forwarding i set in my ubuntu vagrant box
Below is the error on the browser
I found something that could help.
I'm using a RHEL 7.6 and the firewall was on:
$ sudo firewall-cmd --state
running
After disabling:
$ systemctl stop firewalld
$ sudo firewall-cmd --state
not running
I successfully access Jboss console from the outside

Laravel Homestead - How to edit homestead.rb when virtualbox not running?

I attempted the top answer on this thread:
Vagrant port forwarding 80 to 8000 with Laravel Homestead
which was to make this change in the homestead.rb file:
config.vm.network "forwarded_port", guest: 80, host: 8000 to
config.vm.network "forwarded_port", guest: 80, host: 80
I am running a newer version of homestead (not sure where to find the exact version), on a mac.
It did not work, when attempting to start up my homestead virtualbox it now says:
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening on
these ports. The forwarded port to 80 is already in use on the host
machine.
I had edited the homestead.rb file via ssh and vim while the homestead virtualbox was running, but now I can't get it to run and I can't figure out how to undo my changes.
Help with both of these would be greatly appreciated!
How to edit the homestead.rb file when the virtualbox is not running? I believe it is inside either VirtualBox VMs/homestead/homestead.vbox or box-disk1.vmdk, but I do not know how to access inside them.
Help with getting the port to forward correctly to 80 since the solution from the other question did not work.
Homestead 2.+ stores it's files inside your .composer directory inside your User directory. For example, for me it is in:
/Users/noel/.composer/vendor/laravel/homestead
You will find all the configuration and script files that used to reside in the older Homestead 1.0 directories.
Now, since something is holding on to your port 80, it probably means that your local apache installation is running. You can test to see what is holding on to the port by running:
sudo lsof -i :80
To list all processes listening on port 80 (incoming and outgoing).
To stop the local apache you can run:
sudo apachectl stop
That should release the port for you to use with your virtual machine.

Vagrant port forwarding not working. Cups not accesible from host

So I'm working with vagrant and I'm trying to use it as a printing server. I installed cups.
Internally everything works just fine. I can even make a quick curl to my localhost:631 (cups port inside my vagrant) and there's everything.
The thing is I cant access it in any way I try from the host machine.
Obviously I forwarded the port and I've tried with several ports. I've also tried with Debian squeeze and Ubuntu 12.04. Here is my current Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "guruDebian"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 631, host: 6363 ## HERE IS CUPS
end
Any ideas?
I think what you will find is that the default cups config file is locked down to only work from localhost for security reasons.
Inside your Vagrant VM open the /etc/cups/cupsd.conf file and change the following line:
Listen localhost:631
to
Listen 0.0.0.0:631
That should allow you to connect from any host.
Have you tried accessing port 8080 of guest to your host? if no, and the services inside guest are running. then its a firewall issue in guest.
Try to turn firewall temporarily
service iptables off
then try to access it again from host.

Vagrant Port Forwarding on Mac OS X Lion

I've been struggling trying to connect to a centos 6.4 vm using Vagrant.
I'm using salt as a provisioning agent and I have installed apache,php,mysql packages successfully.
When i ssh into the box apache is running fine. I added an index.html file in /var/www and I get the contents back when I curl localhost:80
Vagrant.configure("2") do |config|
## Chose your base box
config.vm.box = "centos63"
config.vm.box_url = ""
## For masterless, mount your salt file root
config.vm.synced_folder "salt/roots/", "/srv/"
## Use all the defaults:
config.vm.provision :salt do |salt|
salt.verbose = true
salt.run_highstate = true
salt.minion_config = "salt/minion"
end
end
Vagrant::Config.run do |config|
config.vm.forward_port 80, 8080
config.vm.share_folder "mypath", "/var/www/leo", "."
end
I ran sudo lsof -i :8080 on my local machine and gave me no results. I also cleared the iptable config in the guest machine with iptables -F. When I curl the guest machine
curl -v 'localhost:8080'
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* Connection refused
* Trying fe80::1...
* Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
Do I need guest additions installed? I looked around on how to install this but I'm not sure if it has to be installed on the host or the guest. Not sure what else to try.
What you are trying to do here isn't possible just using vagrant without running vagrant as root. You can run Vagrant as root i believe but VirtualBox won't agree with that. You can continue to use a port number or if you want or need to use port 80 there is a way.
I had this issue when a client of mine asked me to do a Wordpress Multisite setup. With Wordpress MS you can't have port numbers in the URL b/c some of the URL mapping will not work correctly. I was surprised when I found that out and didn't want to go back to using a program like MAMP.
Anyway here are two ways to achieve this goal (neither are very hard). I'm a Mac user so these are Mac specific Answers, I will see if there is a Windows version and update my answer when I can test it to make sure (see below, there is a way).
Way #1 (Mac IP Firewall Utility):
In your vagrant file
config.vm.forward_port 80, 8080
config.vm.forward_port 443, 8443
Thats pretty normal.
Now open up terminal and you can use the ipfw utility
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to me 80
sudo ipfw add 101 fwd 127.0.0.1,8443 tcp from any to me 443
Now that cmd is not permanent so you would have to re-run the cmd if you restarted your machine. You can make it permanent though and I am including a link below that will explain the rest of way #1.
Web Development on Port 80 and 443 in Vagrant
Way #2 (Mac POW and Anvil):
If you don't have Pow yet, get it! It's a really cool app.
Install Pow and Anvil, you can find Anvil there and you can find Pow there.
You can read the docs on how to set those up but don't pay attention to the "static" and "rack" sites part, you need this part.
You will be using Port Proxying through Pow to take the incoming traffic from mycoolsite.dev and forward it to the virtual machine like mycoolsite.dev:8080 and then the virtual machine will forward 8080 to 80 and back up the line your content will come.
After you install Anvil/Pow and get them set up run this line:
echo 8080 > ~/.pow/mycoolsite
Then click Anvil in the task bar (you may have to refresh it or close and reopen) and turn the site on, thats it, what?? Really? Pow and Anvil rock!!
So there are two ways I have found, I'm sure that there are some things you can do with your Hosts file and I used to do that a bunch. However, these other ways that are available really make it easy to forget about that pesky hosts file.
Note for Windows Users (and Mac users that don't like the first 2 ways): You can use Vagrant Host Manager, you can find out how to set it up here on github. It is a vagrant plugin and basically will edit your hosts file for you, all you do is your vagrantfile config and you are good to go after that. I just tested it on Windows 7 and it worked there so it should be good, if you have any issues just look through the docs on github or file an issue for the Vagrant Host Manager team to review.
I changed the guest port to 5656 and it worked. When running lsof -i :8080 I didn't see any results so i figured nothing was using that port maybe I was wrong.

Resources