Changing domain mapping on Mac OSX etc/hosts to Vagrant Virtual Machine - macos

I've been trying to change the mapping for a domain and forward it to a Vagrant machine that I've forwarded a port to.
The config in Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.network :forwarded_port, host: 4567, guest: 80
end
I've updated /etc/hosts on my Mac OSX with the following:
127.0.0.1:4567 example.com
Yet when I access from my browser example.com nothing changes, I have also tried to map example.com to go to the Google IP without any luck.
What am I overlooking?

I would just add a static ip, or try removing the port number:
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4"
end
Then in your hosts file change it to read:
192.168.50.4 example.com
More info is available here:
https://docs.vagrantup.com/v2/networking/private_network.html

Related

CouchDB on Vagrant VM (Scotch box)

I'm trying to set up CouchDB (and ultimately use PouchDB) on a Scotch Box VM. The VM runs fine, and includes port forwarding for port 5849 by including the code below:
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box-pro"
config.vm.hostname = "scotchbox"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 5984, host: 5984
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "private_network", ip: "192.168.33.10"
The VM runs fine. localhost:8080 will load the PHP home page, and localhost:3000 will load a node script if I have the node server running, but localhost:5984 only returns an empty response when loaded from the browser or from the host machine command line using curl curl: (52) Empty reply from server.
When I have used vagrant ssh to access the VM, I can use curl localhost:5984 to obtain {"couchdb":"Welcome","uuid":"9cabeb8f66947adabe9443594aa7f69c","version":"1.6.0","vendor":{"version":"15.10","name":"Ubuntu"}} as expected.
Here is the guide I've been referring to: https://pouchdb.com/guides/setup-couchdb.html
Additional info: When I go to 192.168.33.10:5984 (instead of using the localhost port forwarding), the result is a refused connection.
Any suggestions as to what my issue might be? I had thought it was a forwarding issue, but the ports 8080 and 3000 work fine, and going to the IP:5984 doesn't work so it makes me wonder. I also thought maybe the service isn't running, but doing ssh on the VM and running curl seems to indicate that it is in fact running.
Thanks!
By default CouchDB bound to a localhost address 127.0.0.1 and you need to re-bind it to 0.0.0.0 to get it accessible from outside of Vagrant box. To do that you need to change parameter bind_address in [httpd] section of default.ini config file or add the same as override in local.ini config file.

Vagrant : why can I not access nginx with domain name?

I am using Vagrant on Windows 10.
I have installed centos 7 vagrant box,it is running correctly.
Vagrantfile is like this:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "dev"
config.vm.hostname = "vagrant-dev"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.33.3"
config.vm.synced_folder "d:/vagrant_env/www/", "/var/www"
end
I installed nginx in centos 7 vagrant box, and I can access nginx welcome page with ip 192.168.33.3.
I want to access it with domain name,so I configure C:\Windows\System32\drivers\etc\hosts
file in windows:
192.168.33.3 www.example.vagrant //add this line into hosts file of windows
and configure /etc/nginx/conf.d/default.conf file in centos 7:
server {
listen 80;
server_name www.example.vagrant;
//...
}
I try accessing www.example.vagrant on windows host,but it does not work.
what should I do?
There's two better solutions to this:
Use xip.io for your address. In this case http://example.192.168.31.3.xip.io/ will route to your address.
Set up a DNS entry for that which can be resolved. An inexpensive .com or .info test domain at a registrar which makes updating easy (e.g. Amazon Route 53) is always handy for this.
Some programs stubbornly refuse to read entries in /etc/hosts or the equivalent in Windows.
Navigate to 192.168.31.3:8080 in your browser. If you can see your server, then just make your redirect like that: 192.168.31.3:8080 www.example.vagrant
config.vm.network "forwarded_port", guest: 80, host: 8080
At this point you are saying "whatever happens inside Vagrant on port 80, forward it to port 8080 on host machine". You have to communicate with your Vagrant machine on port 8080.
Also your IP is wrong 192.168.33.3 vs 192.168.31.3

Vagrant forwarded_port on sub-machine

I couldn't manage to publish a virtual machine's port this way:
config.vm.define "n1" do |n1|
n1.vm.hostname = "n1"
n1.vm.network "private_network", ip: "172.20.20.10"
n1.vm.network "forwarded_port", guest: 8500, host: 8080
end
Access inside the VM works fine:
vagrant#n1:~$ curl http://localhost:8500/v1/health/state/any
but host access (outside of the VM, from my computer web browser) won't work:
http://localhost:8080/v1/health/state/any
Is what I try to achieve possible? Can somebody give me an hint, please?
I am not vagrant expert. BUT, in networking, you CANNOT forward port that bind to localhost(127.0.0.1) without explicitly mentioned it. Universal binding only works for 0.0.0.0.
You may try this, but I wouldn't guarantee it will works
n1.vm.network "forwarded_port", guest: 8500, guest_ip: 127.0.0.1, host: 8080
It is better to start your application binding to IP address then do the forwarding.

Vagrant accessing domain from another guest machine

Now, i have 2 vm machine
First vm running api server.
Second vm acting like client that perform request to the api endpoint.
The api server name is http://api.dev
The client server name is http://client.dev
Here is vagrant file for the api server:
Vagrant.configure(2) do |config|
config.vm.box = "lemp.dev"
config.vm.network "private_network", ip: "192.168.10.10"
config.vm.synced_folder "www", "/var/www/html"
end
Here is vagrant file for the client:
Vagrant.configure(2) do |config|
config.vm.box = "lemp.dev"
config.vm.network "private_network", ip: "192.168.10.11"
config.vm.synced_folder "www", "/var/www/html"
end
Here is host file on my host machine:
192.168.10.11 client.dev
192.168.10.10 api.dev
I can access the http://api.dev from my host machine.
Problem is, i cant access the http://api.dev from my client machine.When i run curl api.dev i got 404 page
What i want is to be able to access to the http://api.dev from another vm instance( the second vm ).
You would need to update the hosts file on the Guests (192.168.10.11 and 192.168.10.10) with the same thing you put on your Host, or you could just use the IPs and not have to worry about doing that.

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.

Resources