Vagrant port forwarding 80 to 8000 with Laravel Homestead - iis

My Problem:
I can only access my sites through port 8000, but not 80, which makes me think it is not redirecting 80 to 8000 as it says it should be. I want to simply type local.kujif.com into my browser and it loads the site, which I read was port 80 by default. I am using curl to check it and it returns:
curl 'http://local.kujif.com'
curl: (7) Failed connect to local.kujif.com:80; No error
However if I add :8000 to the url then it works; it returns my index.php which simply prints 'test':
curl 'http://local.kujif.com:8000'
test
My Details:
I am using Laravel Homestead and Vagrant with Oracle VM VirtualBox.
In the Homestead.rb it has the port forwarding. I haven't edited it at all:
config.vm.network "forwarded_port", guest: 80, host: 8000
config.vm.network "forwarded_port", guest: 3306, host: 33060
config.vm.network "forwarded_port", guest: 5432, host: 54320
I also have Microsoft IIS installed for my work stuff. I obviously stop that service whenever I need vagrant to use the localhost.
"vagrant up" shows:
My Homestead.yaml file:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: /Users/Tyler/.ssh/id_rsa.pub
keys:
- /Users/Tyler/.ssh/id_rsa
folders:
- map: C:\DEV\Linux
to: /var/www/
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
- map: local.kujif.com
to: /var/www/kujif
variables:
- key: APP_ENV
value: local

You should continue to use ports above 1024 since they are non-privileged ports, BUT if you do want you can run as port 80 on the Homestead VM, as long as you don't have anything holding on to that port on the host machine. Just tried it and it worked, with a few gotchas. First, you change that line in the .rb file from:
config.vm.network "forwarded_port", guest: 80, host: 8000
to
config.vm.network "forwarded_port", guest: 80, host: 80
When you fire your VM up after saving you will get a warning from vagrant:
==> default: You are trying to forward to privileged ports (ports <= 1024). Most
==> default: operating systems restrict this to only privileged process (typically
==> default: processes running as an administrative user). This is a warning in case
==> default: the port forwarding doesn't work. If any problems occur, please try a
==> default: port higher than 1024.
==> default: Forwarding ports...
default: 80 => 80 (adapter 1)
But it worked for me. Now, to actually get to the VM I had to use it's private IP instead of the localhost name:
http://192.168.10.10/
But sure enough my site was there and everything was working. If you decide to keep it that was you can add that IP address to your hosts file to give it a nice short name.
Hope this helps.

I see there is an accepted answer, but this alternative may also help someone.
If I understand correctly you really dislike the port "8000"!
Have you tried setting a private network?
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
/*other config stuff here */
config.vm.network :private_network, ip: "192.168.33.22"
This way you can simply use that IP address, or edit you hosts file to map the local domain to that IP.
Take a look at the Vagrant docs:Vagrant Private Networks
BTW, You shouldn't need to shutdown your IIS local server as that is running on a totally different IP range. I have Apache running locally while also accessing the VM server. This allows you to use tools like composer (to pull in laravel) on your local if needed.

I'm not sure what the confusion is - this is the way it's supposed to work.
The web server on the VM listens on port 80. Vagrant/VirtualBox forwards that port from 80 (on the VM) to 8000 (on localhost) so that you can access the site at http://localhost:8000.
Port 80 on the VM's domain name is not going to be available - that domain name probably resolves to localhost.
Try the following: dig local.kujif.com (or nslookup or even ping - I don't know what tools are available on Windows) to find out what IP address that name is resolving to. You will probably find that it's 127.0.0.1 (localhost).
You could try using the IP address set in the homestead file instead: http://192.168.10.10/ - this might work, but it will depend on how networking is configured in the VM.
Ideally, you need to set networking to "bridged" in the VM - this will make the VM look (to your network) like any other device on the network. Other networking options in the VM (sorry, I'm not familiar with the options in VirtualBox) will set the VM up with its own network that is not accessible outside the VM - this is why port forwarding is used to expose network services on the VM.

You can disable the default port forwarding completely by adding the following to the Homestead.yaml:
default_ports: false
Or configure however you like by adding something like:
ports:
- send: 80
to: 80

Related

Connecting to host from inside a docker container on linux requires opening firewall port

Background: I'm trying to have XDebug connect to my IDE from within a docker container (my php app is running inside a container on my development machine). On my Macbook, it has no issue doing this. However, on linux, I discovered that from within the container, the port I was using (9000) was not visibile on the host gateway (Using sudo nmap -sT -p- 172.20.0.1 where 172.20.0.1 is my host gateway in docker).
I was able to fix this issue by opening port 9000 on my development machine (sudo ufw allow 9000/tcp). Once I did this, the container could see port 9000 on the host gateway.
My Question: Is this completely necessary? I don't love the idea of opening up a firewall port just so a docker container, running on my machine, can connect to it. Is there a more secure alternative to this?
From what you've told us, opening the port does sound necessary. If a firewall blocks a port, all traffic over that port is blocked and you won't be able to use the application on the container from the host machine.
What you can do to make this more secure is to specify a specific interface to open the port for as specified here:
ufw allow in on docker0 port 9000 proto tcp
Obviously replace docker0 with the docker interface on your machine. You can find this by looking at the output of ip address show or by following the steps here if the interface name is not obvious.

Cannot connect to neo4j running in droplet but using lynx to navigate to localhost:7474 works, ufw & digital ocean firewall configured

I'm running a brand new droplet in digital ocean running on Ubuntu 18.04.3 (LTS) x64, neo4j status is active and remote interface available on port 7474.
Using lynx via ssh to browse to localhost:7474 works, neo4j is alive and active.
Pinging works
Firewall asigned to allow all traffic but also specifically those ports
Browsing to the ip address on any port does not work
Used ufw to manually add port 80, 443, 7474 to allow access
Cannot connect via browser to the droplet on any port
Firewall configuration:
UFW Status:
Can you make sure the following line in your neo4j.conf file is uncommented :
# With default configuration Neo4j only accepts local connections.
# To accept non-local connections, uncomment this line:
dbms.connectors.default_listen_address=0.0.0.0

How do I access a specific port on a VM in Azure's Resource Manager

I'm trying to relive my university days, by running my own MUD on azure portal, and have run into difficulty when connecting from the outside world.
For those that don't know, this has a fairly simple interface which listens on a port of your choice, and which doles out descriptors as they come in:
https://github.com/InfiniteAxis/SmaugFUSS/blob/master/src/comm.c
I set up an Ubuntu VM in Azure, which has an IP address that I can connect to from my machine via ssh, and successfully compiled and run the mud. I can connect on port 4020 inside the ssh session using telnet, but can't connect to port 4020 from my machine.
netstat -an | grep :4020
tcp 0 0 0.0.0.0:4020 0.0.0.0:* LISTEN
It seems to be listening correctly, so I tried to add an Inbound security rule to the Network Security Group. I gave it a higher priority (lower number) than the ssh rule, which seems to redirect all tcp ports connecting in to 22, but am still unable to connect.
Two rules:
Source: Any, Protocol: TCP, Port: 4020, Destination: Any, Port: 4020
Source: Any, Protocol: TCP, Port: *, Destination: Any, Port: 22
There doesn't seem to be any firewall enabled in Ubuntu (ufw is disabled), but I can't connect.
Anyone got any ideas where I should be looking next? I feel I've missed something really obvious.
You need to set your source port to *, not 4020. This is specifying where traffic is originating from, not where it's going to.

Setting up NGINX / Linux development environment with Vagrant and Chef (Solo)

As a disclaimer I am rather new to Linux after recently moving the Microsoft .NET IIS stack
The problem: I am having difficulty provisioning a ready made environment to develop against using the following...
Vagrant
Chef
VirtualBox
Apt (cookbook)
Apache2 (cookbook)
The error I am receiving is (when hitting the hostname or IP of the virtual machine)
ERR_NAME_NOT_RESOLVED
There is a lot of code so, I will just post my vagrant file and role...
Vagrantfile
-----------------
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.network :forwarded_port, guest: 80, host: 4567
config.vm.host_name = "www.example.vm"
config.vm.provision "chef_solo" do |chef|
chef.cookbooks_path = "cookbooks"
end
end
vagrant-test-boc.rb
-----------------
# Name of the role should match the name of the file
name "vagrant-test-box"
# Run list function we mentioned earlier
run_list(
"recipe[apt]",
"recipe[apache2]"
)
Any suggestions, guidelines examples would be most welcome!
Thanks!
Additional Edit: I have been advised to look into setting up an NGINX server using similar techniques, would this be another question or would it be valid along this thread?
My main resources have been....
https://adamcod.es/2013/01/15/vagrant-is-easy-chef-is-hard-part2.html
https://docs.vagrantup.com/v2/provisioning/chef_solo.html
If I understand correctly, you're trying to access the server www.example.vm (on port 4567) from your host ?
If that's the case, then the issue is probably that you've not told your host that www.example.vm is really an alias to your own host (localhost). Otherwise your host has no way of knowing that it shouldn't do a dns lookup and attempt to send a request to this host over the internet.
On a Unix / OSX box, you can edit your /etc/hosts, where you can add your fake domain name to the localhost line, like so:
127.0.0.1 localhost www.example.vm
Hope this helps! ; )

Vagrant host port ignored

In my Vagrantfile I have the definition of my development machine with a private network ip of 192.168.33.10 and a forwarded port of "guest=80, host=8888", but when a run my vagrant enviroment and I try to run curl -i 192.168.33.10:8888 I get an error saying 'Failed connect to 192.168.33.10:8888; connection refused', but when I try to connect to 192.168.33.10:80 everything it's ok.
My Vagrantfile is:
Vagrant::configure("2") do |config|
config.vm.box = "precise32"
config.vm.define :web do |www|
www.vm.hostname = "apache"
www.ssh.max_tries = 10
www.vm.network :forwarded_port, guest: 80, host: 8888 # Apache port
www.vm.network :private_network, ip: "192.168.33.10"
www.vm.synced_folder "www", "/var/www", :extra => 'dmode=777,fmode=777'
end
end
Why this happens? is vagrant ignoring the forwarded port?
By default Vagrant Boxes use NAT mode, it means that the guests are behind a router (VirtualBox Networking engine between the host and the guest) which maps traffic from and to the virtual machine transparently. The guests are invisible and unreachable from the host.
That's why we need port forwarding. Otherwise services running on guest wont' be accessible.
In your case, you are using Private Network, the guest will be assigned a private IP address that ONLY the host can access, which is 192.168.33.10.
The proper way to access web hosted on the guest is => http://192.168.33.10 from the host.
You have the port forwarding part in the Vagrantfile
www.vm.network :forwarded_port, guest: 80, host: 8888 # Apache port
It is forwarding guest port 80 to your host's 8888. Because you are NOT using NAT mode I am pretty sure it will be ignored. Try to curl -Is http://localhost:8888.
NOTE: even if it still work somehow, you should be accessing web by => http://localhost:8888/ from your host.

Resources