Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I am trying to make a local dev environment so I can work on my site matthewfedak.co.uk.
I am using vagrant and virtual box.
Here is my vagrant file:
Vagrant.configure("2") do |config|
config.vm.box = "lucid32"
config.vm.provision :shell, :path => "localhost.sh"
config.vm.network :forwarded_port, host:4567, guest: 80
config.vm.network :forwarded_port, host: 3306, guest: 3306
config.vm.synced_folder "/Users/mfedak/sites", "/var/www/vhosts", :owner => "www-data", :group => "www-data"
end
Here is my /etc/hosts file:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
#127.0.0.1 localhost
#255.255.255.255 broadcasthost
#::1 localhost
#fe80::1%lo0 localhost
127.0.0.1:4567 matthewfedak.co.uk
127.0.0.1:4567 www.matthewfedak.co.uk
Here is my vhost for the site in /etc/apache2/sites-enabled/matthewfedak.co.uk
vagrant#lucid32:~$ sudo vim /etc/apache2/sites-enabled/matthewfedak.co.uk
<VirtualHost *:80>
ServerAdmin info#matthewfedak.co.uk
ServerName matthewfedak.co.uk
ServerAlias www.matthewfedak.co.uk
DocumentRoot /var/www/vhosts/matthewfedak.co.uk/httpdocs/
ErrorLog /var/www/vhosts/matthewfedak.co.uk/logs/error.log
CustomLog /var/www/vhosts/matthewfedak.co.uk/logs/access.log combined
</VirtualHost>
It sounds simple but I am getting bored of toying with this now. I have setup lots of Ubuntu servers before so don't think that its to with that, just to do with getting the host / remote to communicate.
By default Vagrant uses NAT mode for networking, which requires a lot of port mappings if you are testing a full stack. What's more, due to the limitation of VirtualBox's NAT mode:
Forwarding host ports < 1024 impossible:
On Unix-based hosts (e.g. Linux, Solaris, Mac OS X) it is not possible to bind to ports below 1024 from applications that are not run by root. As a result, if you try to configure such a port forwarding, the VM will refuse to start.
That's why you use port 4567 on host, right?
Now, Root cause is in your /etc/hosts
127.0.0.1:4567 matthewfedak.co.uk
127.0.0.1:4567 www.matthewfedak.co.uk
The hosts file is a simple text file that associates IP addresses with hostnames, one line per IP address. It does NOT work with port numbers.
To work around, consider using bridged mode or vagrant's private network so that you can access the guest using an IP address instead of using host's loopback.
Related
I have drupalvm setup which has drupal installed. In my custom theme, I have styleguide running on port 6006 (can be configured to different as well as it's node app). I want to expose this to host system. when I do vagrant ssh -- -L 6006:localhost:6006 it's works fine and available on host. Now I have added below to Vagrantfile to make this permanent (as per document here - http://docs.drupalvm.com/en/latest/extending/vagrantfile/):
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 6006, host: 6006
end
Now I can see this port forwarded when I do vagrant port But I can't access localhost:6006 (or use already working drupal hostname - local.drupal.com:6006) on host machine. Do I have to add vhost for it in vagrant, if yes how? OR is there any other way to expose node app to host?
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
I want to access kibana running on my local system to be accessed by local_ip:5601 on other systems in my local network. I tried adding these two lines in elastic search:
http.cors.allow-origin: "*"
http.cors.enabled: true
But, it didn't work either.
On your kibana.yml look for the line #server.host: "0.0.0.0". It will probably be commented (#). You must remove the "#" from the line and restart your kibana service. It should allow you to access kibana from your local network ip e.g. "192.168.10.20" and make it discoverable by your other systems.
On that same file kibana.yml you will find an url that points to "http://localhost:9200" by default. If your elasticsearch instance is hosted in any different url than that, you must specify to kibana config file.
You can find more information about it here
See this related question:
vagrants-port-forwarding-not-working
I was working with Kibana in a Centos 7 Vagrant VM.
I was not able to access the Kibana webui from the Host computer.
Stopping firewalld and disabling SELinux did not do the trick.
My VM ip address was 192.168.2.2, so I tested with curl http://92.168.2.2:5601/ and it would work from within the VM, but not from the Host CLI.
I tested that port forwarding was working by installing Apache in the VM and could access it from the Host browser with http://localhost:80, so port forwarding was not the problem.
My problem was the server.host parameter in the kibana.yml configuration file, which I had set to the ip address of the VM.
I changed it from this:
server.host: "192.168.2.2"
to this:
server.host: "0.0.0.0"
restarted kibana and could access the webui from the Host.
This is how I got it to work:
Vagrantfile:
config.vm.network "forwarded_port", guest: 5601, host: 5602
httpd.conf:
Listen 5602
<VirtualHost *:5602>
ProxyPreserveHost On
ProxyRequests Off
ServerName kibana.mydomain.dev
ProxyPass / http://127.0.0.1:5601/
ProxyPassReverse / http://127.0.0.1:5601/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
Let's say I make two vagrant boxes, foo and bar:
$ mkdir -p foo bar
$ pushd foo; vagrant init hashicorp/precise32; vagrant up; popd
$ pushd bar; vagrant init hashicorp/precise32; vagrant up; popd
Now let's say I start an HTTP server on foo:
$ cd foo
$ vagrant ssh -c 'python -m SimpleHTTPServer 8080
My question is, how can I get bar to communicate (e.g. via curl) with foo?
$ cd bar
$ vagrant ssh -c 'curl http://????'
Although the question does not make it clear, I think this older question is asking:if the *same* development machine is running two vagrant instances, how can an app running onfoofetch data from a url onbar`.
If so, I ran into this recently for my two Rails apps(each running in a separate vagrant instance on the same development machine).
The two-part 'trick' if foo wants to fetch data from bar, is:
1) each Vagrant files needs a line:
config.vm.network :private_network, ip: PVT_NETWORK
where PVT_NETWORK is a local IP, is different for each Vagrant file, and probably needs to be in the same subnet. For example PVT_NETWORK might be 192.168.50.50 (foo) and 192.168.50.51 (bar)
2) foo accesses bar via the PVT_NETWORK IP address not the "real" IP you would use with a web browser.
In my Rails example, I also have each app running on a different port, so foo is on localhost:3000 and bar is on localhost:3001, so foo would access a url on bar via
http://192.168.50.51:3001/some_url
If the two servers are in the same network and no ACL between them (local boxes) they can communicate with each other after configuring the network.
configure the vagrant file:
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
The scenario is that my dev environment is on a Vagrant box on my laptop (host) and I would like to do browser testing in a vitualbox vm, so I need to see one vm from another.
The vagrant box's port is :8080 which is forwarded to the host on the same port :8080. So I can see the server from the host at localhost:8080
Which address should I be using for the browser testing vm?
The testing vm's default gateway?
The vagrant vm's ip?
The host's virtual network ip?
And should I be using a NAT or host only adapter on the browser testing vm?
That makes for a lot of combinations, all of which I believe I have tried. What else do I need to understand here?
In your use case, you should be using Bridged networking (Public Network in Vagrant). If the VMs reside on the same host, you can even use internal (Private Network in Vagrant).
If using Public Network, the VM's 2nd NIC will be able to obtain an IP address from the DHCP server in your network (e.g. your home router).
Simply add the following code block in your Vagrantfile and do a vagrant reload
Vagrant.configure("2") do |config|
config.vm.network "public_network"
end
You should be able to get the IP address by using vagrant ssh and ifconfig / ip addr show.
In case you don't want to go with public_network just like me then you should do the steps below using private_network:
Open Vagrantfile from your project root
Search for config.vm.network
Add this line config.vm.network "private_network", ip: "192.168.33.10". Remember this is not the IP of your base machine it's a virtual-box IP address and your machine IP should be different. You can say it's a fake IP address so change it to anything else like 192.168.30.20.
Reload your vagrant using vagrant reload.
Now go to your other virtual guest in my case it's the Windows Guest 2. My base is Linux Mint Vagrant box is on Ubuntu Guest 1. Open C:\Windows\System32\drivers\etc\hosts file as admin and do the above IP's entry in there like 192.168.33.10 local.youralias.com. And save the file, after that you can now browse the site now at http://local.youralias.com/.
In case your guest 2 is also Linux just edit this file sudo vi /etc/hosts, and add this line at top of it 192.168.33.10 local.youralias.com. Now save and exit and browse the URL :)
Enjoy! Happy coding.
Adding to accepted answer, you can actually set IP and specify which network interface to use.
My setup on linux box via wifi and static IP:
You can find your wifi interface name by running ifconfig command.
Vagrant.configure("2") do |config|
config.vm.network "public_network", :bridge => 'wlp8s0', ip: "192.168.1.199"
end
This may have many source cause. In my case, I use vagrant fedora boxe.
I tried:
First using the private_network that I attached to a host only adapter and launched httpd service to test the connection between guest and host
config.vm.network "private_network", type: "dhcp", name: "vboxnet2"
config.vm.network "forwarded_port", guest:80, host:7070
but I was not able to ping my guest machine from the host and could no telnet the httpd service opened
Second using public_network and launched httpd service to test connectivity
config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", use_dhcp_assigned_default_route: true
I could ping my guest from my host but I could not telnet the httpd service.
For this two use case, the issue was that the port 80 on the fedora guest host was blocked by the firewall. Here is what fixed the issue and get all working for both privat_network and public_ntwork:
firewall-cmd --permanent --add-port 80/tcp #open the port permanently
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --list-port # list to check if the port was opened
systemctl stop firewalld # stop and open the firewall service
systemctl start firewalld
Old question, new answer: [disclaimer: i am not a vagrant expert]
both solutions might work but the solution in the "vagrant way of thinking" is that some component in your guest (rinetd?) should forward any requests to unknown ports to the host. From the host the request could then be mapped (via vagrant port forwarding) to a services that is running in the other guest.
So, to resume:
1.in guest-1 we do localhost:1234. Guest-1 will detect that this port is not available and forward to host
2. the host will check the vagrant port forwarding and forward to guest-2
3. in guest-2 we have some nice service listening to post 1234
4. done.